Create PDF in memory instead of physical file using C#

Posted by acadia on Stack Overflow See other posts from Stack Overflow or by acadia
Published on 2010-05-12T02:17:54Z Indexed on 2010/05/12 2:24 UTC
Read the original article Hit count: 477

Filed under:

Hello, How do one create PDF in memorystream instead of physical file using itextsharp.

The code below is creating actual pdf file.

Instead how can I create a byte[] and store it in the byte[] so that I can return it through a function

using iTextSharp.text;
using iTextSharp.text.pdf;
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
doc.Open();//Open Document to write
Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
Phrase pharse = new Phrase("This is my second line using Pharse.");
Chunk chunk = new Chunk(" This is my third line using Chunk.");

doc.Add(paragraph);

doc.Add(pharse);

doc.Add(chunk);
doc.Close(); //Close document

© Stack Overflow or respective owner

Related posts about c#