Skip to main content
Skip table of contents

pdfOCR module - onnxTR

With the release of iText Suite 9.0.3 (pdfOCR 4.1.0), we have also released a new pdfOCR module, called pdfocr-onnxtr, which enables us to use Open Neural Network Exchange (ONNX) compatible models with iText.

It is really super easy, especially if you are already familiar with the pdfOCR API (Java/.NET).

Java

JAVA
IDetectionPredictor detectionPredictor = OnnxDetectionPredictor.fast(FAST);
IRecognitionPredictor recognitionPredictor = OnnxRecognitionPredictor.crnnVgg16(CRNNVGG16);
OnnxTrOcrEngine ocrEngine = new OnnxTrOcrEngine(detectionPredictor, recognitionPredictor);

OcrPdfCreator ocrPdfCreator = new OcrPdfCreator(ocrEngine);
try (PdfWriter writer = new PdfWriter(PATH_TO_OUTPUT_PDF)) {
    String imagePath = "src/images/rotatedBy90Degrees.png";
    PdfDocument pdf = ocrPdfCreator.createPdf(Collections.singletonList(new File(imagePath)), writer);
}

You will notice, though, that with the OnnxTrOcrEngine constructor, there are two arguments that go into it.

  • Detection - this is the predictor that identifies where there is text present in the document.

  • Recognition - this is the predictor that identified which is present where the detection predictor said it would.

Even though by supporting ONNX we theoretically support multiple engines, the current ones we recommend are the following:

You will have to download the model .onnx files and use them for OnnxDetectionPredictor.fast() and OnnxRecognitionPredictor.crnnVgg16() respectively

For complete tests that are part of our functional tests, be sure to check our GitHub repository for our Java and .NET tests.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.