Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.SMALL_PAPERBACK, 10, 10, 42, 35);
iTextSharp.text.pdf.PdfWriter wri1 = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, memStream);
doc.Open();//Open Document to write
iTextSharp.text.Paragraph paragraph1 = new iTextSharp.text.Paragraph("memStream.EndWrite()");

iTextSharp.text.Phrase pharse = new iTextSharp.text.Phrase("This is my second line using Pharse.");
iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(" This is my third line using Chunk.");

doc.Add(paragraph1);

//doc.Add(pharse);

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

byte[] content = memStream.ToArray();

// Write out PDF from memory stream. 
using (FileStream fs = File.Create("D:\\Test.pdf"))
{
	fs.Write(content, 0, (int)content.Length);
}
Posted
Updated 7-Apr-15 19:57pm
v4
Comments
Sinisa Hajnal 8-Apr-15 2:12am    
And the problem is...what exactly? What would you expect in the document. Do you get any exceptions? Or just empty document. Where did you get memStream from? Do you know it is not empty?

1 solution

This is only a guess, but based on the information that you have given it's the best I can do:

Try putting
C#
doc.Close();
AFTER the
C#
Using
{
   ...
}
where you write the file.

Closing the document might or might not dispose of the memory stream?!?!?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900