Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PDF created with iTextSharp cannot be opened by Acrobat Reader?

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

like image 362
Rasto Avatar asked Aug 13 '10 12:08

Rasto


1 Answers

Problem was solved after restarting VS. No code change was made.

like image 68
Rasto Avatar answered Sep 28 '22 05:09

Rasto