Search code examples
pdfitextacrobatfoxit

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?


Solution

  • 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.