3

My application is generating PDF documents using itext#. The files open fine and display correctly in Foxit Reader but in Adobe Acrobat it errors with:

There was an error processing page. There was a problem reading this document (109).

Why will the file open in one but not the other?

John Mills
  • 9,390
  • 11
  • 69
  • 113
  • also, apart from the above message when opening the document in Acrobat Reader, the Internet Explorer Acrobat Reader add-on / extension viewer that opens by default when requesting the PDF in question from a server, would give me the following message (code after Local\ sometimes changing) : Object label badly formatted. Local\EWH-1884-0 – hello_earth Jul 29 '15 at 09:53

2 Answers2

6

This was my code:

        var document = new Document(_pageSize, PageMargin, PageMargin, PageMargin, PageMargin);
        var writer = PdfWriter.GetInstance(document, output);
        writer.CloseStream = false;
        writer.PageEvent = new Footer(HeaderFont, _defaultFont.BaseFont, report.Name);
        document.Open();

        if (report.Results.Any())
            document.Add(CreateTable(report.Results, report.Types, report.RootType));
        else
            document.Add(new Paragraph("No results", _defaultFont));

        writer.Close();

After adding the line document.Close(); before the writer.Close(); line, it now shows in both Foxit and Acrobat.

I guess a key thing with itext# is to be very careful that objects are closed properly. This probably reflects it is a ported library and not a library built for .NET from the ground up.

John Mills
  • 9,390
  • 11
  • 69
  • 113
  • 1
    Adding the line document.Close() before the writer.Close() caused program to crash. writer.Close() expects the document to still be available. – Steve Staple Oct 23 '14 at 13:59
  • 2
    As in all exemples from the itext book, use Document.close(). PdfWriter.close() is not needed, and cause the resulting pdf to be corrupted. – cghislai Jun 01 '15 at 14:24
  • in my case, I was wrapping both Document & PdfWriter in clauses - I feel that some kind of Close might be called along with implicit Dispose, as the result of the , on PdfWriter - I got rid of and moved explicit calls to Dispose, both for Document & PdfWriter, to finally block - the problem got solved, thanks to this thread – hello_earth Jul 29 '15 at 09:44
  • It worked when I removed writer.close(). Thanks it helped! – Syed Jun 28 '17 at 08:21
2

Some pdf readers are more tolerant in various areas than others. Foxit probably ignores bits in a pdf that it doesn't support. Different versions of acrobat choke on different things, just to muddy the waters. Without seeing the PDF in question, all we've got is guesswork.

Mark Storer
  • 15,209
  • 2
  • 37
  • 75