With PDF for .NET, you can write content directly into a web page's output buffer with no temporary files. To do so, follow the steps mentioned below to create Web Application with PDF for .NET.
C# |
Copy Code
|
---|---|
using C1.Pdf; using System.Drawing; |
C# |
Copy Code
|
---|---|
public void OnGet() { C1PdfDocument pdf = new C1PdfDocument(); Font font = new Font("Arial", 12); RectangleF rect = new RectangleF(72, 72, 100, 50); string text = "Some long string to be rendered into a small rectangle. "; text = text + text + text + text + text + text; // Center align string. StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; pdf.DrawString(text, font, Brushes.Black, rect, sf); pdf.DrawRectangle(Pens.Gray, rect); RenderPDF(pdf); } |
C# |
Copy Code
|
---|---|
protected void RenderPDF(C1PdfDocument doc) { // Render PDF document into memory-based // PDF stream. MemoryStream ms = new MemoryStream(); doc.Save(ms); // Get response object. int length; HttpResponse rsp = this.Response; // Clear it rsp.Clear(); // Write PDF stream into response buffer rsp.ContentType = "Application/pdf"; length = (int)ms.Length; rsp.Body.Write(ms.GetBuffer(), 0, length); } |