ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.08k stars 237 forks source link

Unable to read page count for older versions of PDF. #298

Open veera-raghavagupta opened 2 years ago

veera-raghavagupta commented 2 years ago

While uploading the pdf document (Version 1.4) when we try to read the page count of the PDF file is throwing error from below line of code.

int pageCount = PdfReader.Open(memoryStream, PdfDocumentOpenMode.ReadOnly).PageCount;

Exception Details: Invalid entry in XRef table, ID=2, Generation=0, Position=118, ID of referenced object=2, Generation of referenced object=65536

Can somebody help me on this?

aabiryukov commented 2 years ago

You can ignore these non critical errors with the option PdfReadAccuracy.Moderate.

Full code: int pageCount = PdfReader.Open(memoryStream, PdfDocumentOpenMode.ReadOnly, PdfReadAccuracy.Moderate).PageCount;

isujeewa commented 1 year ago

I'm encountering a similar problem. I'm attempting to utilize the PdfReadAccuracy.Moderate enumeration, but I'm unable to locate an overload method signature for PdfReader.Open(memoryStream, PdfDocumentOpenMode.ReadOnly, PdfReadAccuracy.Moderate). Could you please advise me on which version I should be using? Currently, I am working with PdfSharpCore -Version 1.3.57.

lornewilson commented 1 year ago

For further clarification. I am also using version 1.3.57, and the solution described by @aabiryukov works just fine and solved the problem we had reading old PDFs.