Automatic rotation of pages via ABBYY FineReader Engine

  • 171 Views
  • Last Post 05 June 2017
Koen de Leijer posted this 02 May 2017

Via the following post it should be possible to rotate images via FineReader Engine

http://forum.ocrsdk.com/thread/588-rotation-image-via-fine-reader-engine/

In one of the reactions a pointer has been given to some (what seems) .NET-code

Is there any chance of a sample in Java (for the com.abbyy.finereader jar) or Java-documentation in any kind?

At the moment we fully OCR an image but like to automatically rotate if a landscape page has been scanned in portrait mode

    private final static String DLL_FOLDER = "/opt/ABBYY/FREngine11/Bin";
    private final static String DEVELOPER_SN = "SWED....................";
    private void ocrPdf(String inputPdfFilename, String outputPdfFilename) throws Exception {
        //init FREngine/IEngine with default profile
        IEngine engine = Engine.GetEngineObject(DLL_FOLDER, DEVELOPER_SN);
        engine.LoadPredefinedProfile("DocumentConversion_Accuracy");

        //create new document and insert PDF
        IFRDocument document = engine.CreateFRDocument();
        document.AddImageFile(inputPdfFilename, null, null);
       
        //process full document
        document.Process(null);
       
        // Save results to pdf using 'balanced' scenario
        IPDFExportParams pdfParams = engine.CreatePDFExportParams();
        pdfParams.setScenario( PDFExportScenarioEnum.PES_Balanced );

        //export PDF to disk and close handle with document
        document.Export(outputPdfFilename, FileExportFormatEnum.FEF_PDF, pdfParams);
        document.Close();
    }

Order By: Standard | Newest | Votes
Lilya Chesnova posted this 25 May 2017

Hi Koen de Leijer, 

As far as I know you have already received the answer from our technical consultant. I will duplicate this answer here too: 

Java-documentation and samples: ABBYY SDKs does not have documentation in JavaDoc format. Documentation in PDF and HTML formats can be found in the Help subfolder of SDK’s distributive.

All available samples can be found in "...\FineReader Engine\Samples" folder after installation with the default parameters.

Rotation: You need to set to TRUE setting CorrectOrientation (DocumentProcessingParams -> PageProcessingParams -> PagePreprocessingParams).

Additional settings for orientation correction are available through OrientationDetectionParams (DocumentProcessingParams -> PageProcessingParams -> PagePreprocessingParams).

Koen de Leijer posted this 26 May 2017

Hi Lilya

Thanks !

Both the samples and menu-options were not helpful because we use the Finereader Engine directly from Java. In FREngine11UserGuide.pdf there was a sample in C++/C# that leaded me to the following Java-statements:

        IDocumentProcessingParams dpp = engine.CreateDocumentProcessingParams();   
        dpp.getPageProcessingParams().getPagePreprocessingParams().setCorrectOrientation(true);

Full working solution

    private final static String DLL_FOLDER = "/opt/ABBYY/FREngine11/Bin";
    private final static String DEVELOPER_SN = "SWED....................";
    private void ocrPdf(String inputPdfFilename, String outputPdfFilename) throws Exception {
        //init FREngine/IEngine with default profile
        IEngine engine = Engine.GetEngineObject(DLL_FOLDER, DEVELOPER_SN);
        engine.LoadPredefinedProfile("DocumentConversion_Accuracy");

        //create new document and insert PDF
        IFRDocument document = engine.CreateFRDocument();
        document.AddImageFile(inputPdfFilename, null, null);
       
        //enable orientation detection
        IDocumentProcessingParams dpp = engine.CreateDocumentProcessingParams();   
        dpp.getPageProcessingParams().getPagePreprocessingParams().setCorrectOrientation(true);
               
        //process full document
        document.Process(dpp);
       
        // Save results to pdf using 'balanced' scenario
        IPDFExportParams pdfParams = engine.CreatePDFExportParams();
        pdfParams.setScenario( PDFExportScenarioEnum.PES_Balanced );

        //export PDF to disk and close handle with document
        document.Export(outputPdfFilename, FileExportFormatEnum.FEF_PDF, pdfParams);
        document.Close();
    }

  • Liked by
  • Lilya Chesnova
Lilya Chesnova posted this 05 June 2017

Thank you for sharing this solution! 

Close