I create simple test PDF document using iTextSharp. I'm just using PdfContentByte to show some text. This is the code:
Document document = new Document();
Stream outStream = new FileStream("D:\\aaa\\test.pdf", FileMode.OpenOrCreate);
PdfWriter writer = PdfWriter.GetInstance(document, outStream);
document.Open();
PdfContentByte to = writer.DirectContent;
to.BeginText();
to.SetFontAndSize(BaseFont.CreateFont(), 12);
to.SetTextMatrix(0, 0);
to.ShowText("aaa");
to.EndText();
document.Close();
outStream.Close();
The file is created but when I try to open it(using Acrobat Reader), all I get is following message:
There was an error opening this document. There was a problem reading this document (14).
Where is the problem ? How do I fix it? Thank you
Problem was solved after restarting VS. No code change was made.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With