davidshomelab / PdfTools

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

invalid entry in XRef table #44

Open stan-spotts opened 1 year ago

stan-spotts commented 1 year ago

Not sure if anyone is even looking here as it appears it's been a few years since there was activity, but...

I got this error when trying to join two documents:

Join-PDFDocument : Invalid entry in XRef table, ID=1, Generation=0, Position=133821, ID of referenced object=61, Generation of referenced object=0

I searched and it seems that it happens because one of the documents may have some level of corruption. Oddly, it renders just fine. In any case, the guidance I got indicated that if the PdfReader.Open method here:

            foreach (string SourceFile in SourceFiles)
            {
                **pdfDocuments.Add(PdfReader.Open(SourceFile, PdfDocumentOpenMode.Import));**
            }

is modified to use an overload method like so:

pdfDocuments.Add(PdfReader.Open(SourceFile, PdfDocumentOpenMode.Import, PdfReadAccuracy.Moderate));

it will at least not throw the error.

davidshomelab commented 1 year ago

I've had a look at this and unfortunately it looks like the PdfReadAccuracy argument only exists in the .net core and .net standard versions of the PDFSharp module so would require a fairly significant rewrite of the module to implement and may break compatibility with PowerShell 5. If the document you had issues with isn't confidential I'd love to take a look at it to see if there are any workarounds that would be simpler to implement

davidshomelab commented 1 year ago

Found a bit more time to look at this and realised that it wasn't actually as hard as I thought it would be. I've created a test release here https://github.com/davidshomelab/PdfTools/releases/download/%2344.1/PsPDF.44-1.zip, can you please confirm if this solves your issue?