Welcome Guest Search | Active Topics | Sign In | Register

Modifying a generated (tagged) PDF corrupts the file Options
Phil
Posted: Wednesday, March 19, 2025 1:23:34 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 71
Hi I have a PDF that has been generated with the latest EO-PDF version (25.1.22) with GenerateTags=true.

I then open the PDF in Acrobat Reader and it is marked Tagged=Yes - all is OK - I can also open this file in PAC (PDF Accessibility Checker - https://pac.pdf-accessibility.org/en)

I then use the same code and add the following code after the generation...

Code: C#
EO.Pdf.PdfDocument doc = null;
MemoryStream stream = null;

using (stream = new MemoryStream())
{
    stream.Write(pdfResult, 0, pdfResult.Length); //pdfResult is the byte[] containing the original (generated) PDF that was OK
    stream.Seek(0, SeekOrigin.Begin);
    doc = new EO.Pdf.PdfDocument(stream);
    doc.Info.Title = "My title";
    doc.Language = "eng";
    doc.Save(stream);
}
pdfResult = stream.ToArray();

...I then open the PDF in Acrobat Reader and I get a message that appears in a dialog box for a fraction of a second (you may miss this) saying "File is corrupted but is being repaired" - the file is viewable in Acrobat Reader and is marked Tagged=Yes - when I close the file I get a dialog asking to Save the file (as it has been repaired/modified by Acrobat Reader) - if I save this file, it (the saved file) opens fine in PAC - if I *don't* save, it (the unsaved file) does *not* open in PAC - I get a message saying "The PDF document is corrupted and unfortunately it can't be read by PAC (Cross reference section not found at offset: 99537)". Note that both the saved and unsaved PDF files open without an issue in Chrome, Edge, FF. Also note the saved file was dramatically smaller than the unsaved file.

I seem to have similar issues when modifying post-generation (merging, adding footers, etc) existing tagged documents - is there something I am doing wrong here ?
eo_support
Posted: Wednesday, March 19, 2025 4:34:24 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,312
Hi,

Can you try to isolate the problem into a small test project and send the test project to us? See here for more details:

https://www.essentialobjects.com/forum/test_project.aspx

Thanks!
Phil
Posted: Monday, March 24, 2025 5:13:28 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 71
Thanks for the reply - to confirm the issue was at my end - the issue was that after writing the PdfDocument in the stream (followed by updating the PdfDocument), I was not closing off the stream before saving the updates to the stream - this process corrupted the PDF - solution was to close off the first stream then create a new one to save to the stream
eo_support
Posted: Monday, March 24, 2025 9:54:07 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,312
I see. Thank you very much for the update. Glad to hear that the issue is resolved.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.