An error occurs when processing a PDF file: C:\Build\TeamAgent\_work\1\s\0\OCRT\PdfTools\PdfService\Src\PdfDocument.cpp, 191.


When a PDF file is being processed, the following error occurs:

C:\Build\TeamAgent\_work\1\s\0\OCRT\PdfTools\PdfService\Src\PdfDocument.cpp, 191.


This error may occur if the PDF file does not conform to the PDF specification, and the PDF header has some data inserted before the %PDF- part of the header.


The issue can be resolved by removing the extra data from the PDF file before opening it. It can be done manually via a text editor, or programmatically before loading the file into FineReader Engine.

C# code:

IFRDocument frDocument = engine.CreateFRDocument();
// Read the file data as a string
string badImagePath = "bad.pdf";
string badPdfData = System.IO.File.ReadAllText(badImagePath, System.Text.Encoding.Default);
// Find the position of the %PDF- part of the header
int pdfHeaderPos = badPdfData.IndexOf("%PDF-");
// Strip the extra data
string pdfData = badPdfData.Substring(pdfHeaderPos);
// Write the modified PDF data into a file
string imagePath = "good.pdf";
System.IO.File.WriteAllText(imagePath, pdfData, Encoding.Default);
// Load the modified PDF file into FineReader Engine

Have more questions? Submit a request



Please sign in to leave a comment.