I'm encountering an exception that I can't seem to recover from while using .NET v8 and making a call to PdfAddGdPictureImageToPdfOCR. We're converting PDFs to image-only PDFs of itself. This involves looping over each page in PDF #1 and rendering it to gdpicture image and then saving it to PDF #2.
The exception that seems to be blowing up the program is an System.AccessViolationException from within GdPicturePro .NET's PdfAddGdPictureImageToPdfOCR function. This does not seem to be recoverable and causes the application the crash. I also see some output to the console that seems to come from within GdPicturePro itself, saying "Image too large (2102, 33042)".
The page that we are rendering to image and putting into a new PDF + OCRing it is definitely very large. We did page sizes this large in the v7 edition. At the very least, in the v7 edition we were able to catch the exception and continue to the next page. The v8 function call seems to blow up the whole thing and causes the entire operation to halt. The PDF itself also has about 600 pages, and when I remove the individual page causing the crash and PDF it alone it works, but when it comes up in the original PDF (it's page 406), it crashes.
I will paste my code below as well as attach a screenshot of the exception. Any ideas on how to prevent this?
- Code: Select all
// flatten the original pdf into image only pdf
if (the_pdf.LoadFromFile(file_original, false) == GdPictureStatus.OK)
{
// create the final OCRed pdf
int ocr_id = the_imaging.PdfOCRStart(file_produced, false, "", "", "", "", "");
int page_count = the_pdf.GetPageCount();
for (int x = 1; x <= page_count; x++)
{
Console.WriteLine("Flattening and OCRing page {0} of {1}.", x, page_count);
// activate the current page
if (the_pdf.SelectPage(x))
{
try
{
// rasterize the active page
int image_id = the_pdf.RenderPageToGdPictureImage(200, true);
if (image_id > 0)
{
the_imaging.PdfAddGdPictureImageToPdfOCR(ocr_id, image_id, "eng", dictionaries, "");
the_imaging.ReleaseGdPictureImage(image_id);
}
else
{
Log(String.Format("Could not rasterize page {0}.", x));
}
}
catch (Exception ex)
{
Log(ex.Message);
}
}
else
{
Log(String.Format("Could not select page {0}.", x));
}
}
// stop the OCRing
the_imaging.PdfOCRStop(ocr_id);
// close the original pdf
the_pdf.CloseDocument();
}
else
{
Log(String.Format("Error opening original pdf; {0}.", file_original));
}
