Question:
I want to increase OCR performance by not OCRing a PDF page that does not require OCR.
Answer:
The Apryse Server SDK provides the OCROptions.AddIgnoreZonesForPage() method, which allows you to define regions of a PDF page that should be excluded from OCR processing. By preventing OCR from analyzing content that is already searchable or otherwise unnecessary, you can significantly reduce processing time and improve overall OCR performance.
For even greater optimization, OCRModule.PageNeedsOCR() can be used to determine whether a page requires OCR at all. When a page already contains searchable text, you can add an ignore zone that covers the entire page, effectively skipping OCR processing for that page and avoiding unnecessary work.
- Added in Apryse Server SDK version 12.2.0
Example: Here we check the PDF page requires OCR and add and an ignore zone for the entire page if it does not.
using (PDFDoc pdf_doc = new PDFDoc($"{inut_file_name}.pdf"))
{
pdf_doc.InitSecurityHandler();
OCROptions options = new OCROptions();
RectCollection ignoreZone = new RectCollection();
PageIterator itr = pdf_doc.GetPageIterator();
while (itr.HasNext())
{
Page page = itr.Current();
bool needsOCR = OCRModule.PageNeedsOCR(page, true);
if (OCRModule.PageNeedsOCR(page, true))
{
ignoreZone.AddRect(page.GetMediaBox());
options.AddIgnoreZonesForPage(ignoreZone, itr.GetPageNumber());
}
itr.Next();
}
OCRModule.ProcessPDF(pdf_doc, options);
string output_file = $"{output_file_name}.{version}.pdf";
pdf_doc.Save(output_file, SDFDoc.SaveOptions.e_linearized);
}
An additional option that may increase performance would be to extract the PDF pages and OCR them separately, see our example PDF page manipulation.