PdfSharpCore icon indicating copy to clipboard operation
PdfSharpCore copied to clipboard

Unable to read page count for older versions of PDF.

Open veera-raghavagupta opened this issue 2 years ago • 3 comments

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?

veera-raghavagupta avatar Sep 23 '22 11:09 veera-raghavagupta

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

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

aabiryukov avatar Dec 02 '22 07:12 aabiryukov

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.

isujeewa avatar Aug 06 '23 20:08 isujeewa

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.

lornewilson avatar Aug 18 '23 16:08 lornewilson