Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDF document generated using itext# opens in Foxit but not Acrobat

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?

like image 620
John Mills Avatar asked Jan 24 '26 07:01

John Mills


2 Answers

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.

like image 98
John Mills Avatar answered Jan 27 '26 00:01

John Mills


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.

like image 30
Mark Storer Avatar answered Jan 27 '26 00:01

Mark Storer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!