We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Constructor PdfLoadedDocument(String) fails on certain PDF's

Dear All

One seemingly very simple problem:

The coded line:

using PdfLoadedDocument pdfDocument = new PdfLoadedDocument(currentDocument);
... fails on certain PDF's.

currentDocument contains the correct String with Path & File Name.

I get - depending on PDF's, just a vague estimation - two different messages:

  1. PDF's with mixed landscape/portrait pages:
    "Syncfusion.Pdf.PdfException: The index was outside of the array" (roughly translated)
    at Syncfusion.Pdf.Parsing.PdfLoadedDocument.LoadDocument(Stream file)
    ..."
  2. A PDF form brings - at the exact same line - the following error message:
    " Syncfusion.Pdf.PdfException: Invalid cross reference table.
    bei Syncfusion.Pdf.Parsing.PdfLoadedDocument.LoadDocument(Stream file)
    bei Syncfusion.Pdf.Parsing.PdfLoadedDocument..ctor(Stream file)
    ..."
All other PDF's are working well...

Any hints?

Greets from Switzerland - Christoph

1 Reply

IJ Irfana Jaffer Sadhik Syncfusion Team May 5, 2023 01:52 PM UTC

PDF's with mixed landscape/portrait pages:

"Syncfusion.Pdf.PdfException: The index was outside of the array" (roughly translated)

at Syncfusion.Pdf.Parsing.PdfLoadedDocument.LoadDocument(Stream file)..."

The "Index was outside of the array" exception occurs when you try to access an index in an array that is either larger or smaller than the bounds of the array.

If the page tried to load is greater than the total number of pages in a PDF document, an exception called "ArgumentOutOfRangeException" is raised


A PDF form brings - at the exact same line - the following error message:

" Syncfusion.Pdf.PdfException: Invalid cross-reference table.

bei Syncfusion.Pdf.Parsing.PdfLoadedDocument.LoadDocument(Stream file)

bei Syncfusion.Pdf.Parsing.PdfLoadedDocument..ctor(Stream file)

..."


The "Invalid cross reference table" exception occurs when the cross-reference table of a PDF document is corrupt or invalid. The cross-reference table is used to locate the objects within a PDF document, and if it is corrupted, the PDF viewer or library may not be able to properly locate the objects within the document.


The cross-reference table is an essential part of a PDF file, and it is used to keep track of the location and status of each object in the file. If this table is not properly formatted, the PDF viewer may not be able to read the document.

The reported pdf is corrupted with the following corruptions: “Invalid cross reference table”,” The document has no calatog object”. We can able to repair the corrupted pdf document with open and repair overload available in the PdfLoadedDocument instance, we have already added the details in our documentation.


Please use the following code snippet to load a pdf document in open and repair mode:

//Open an existing corrupted document from disk.

PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf", true);


Please find some of the following corrupted error messages that cannot be repaired suing our PDF library:
https://help.syncfusion.com/file-formats/pdf/open-and-save-pdf-file-in-c-sharp-vb-net#possible-error-messages-of-invalid-pdf-documents-while-loading


Please refer the below links for more information,

https://help.syncfusion.com/file-formats/pdf/working-with-document#find-corrupted-pdf-document

https://www.syncfusion.com/blogs/post/how-to-find-corrupted-pdf-files-in-c-sharp.aspx



follow the below links for more information,

https://www.syncfusion.com/blogs/post/how-to-find-corrupted-pdf-files-in-c-sharp.aspx


We request you try this on your end and let us know the result. If still you are facing the issue, we request you to share the modified sample or input document with us. so that we can assist with you further in this


Loader.
Up arrow icon