Page 1 of 1

OCR_SaveW gives first time 0, all others -2147418113

Posted: Thu Mar 18, 2021 2:23 pm
by baumunk
When I make multiple PDF searchable,

I always get at call OCR_SaveW value -2147418113, at second and further PDF. At first is 0.

Why?

OCR_Init and OCR_Finalize is called for each file.

Code:

Code: Select all

private void MakePDF_OCR(PDFConverterParameter par)
        {
            var data_path = $@"{Umgebung.NoRAProg}\OCRLanguages\";
            var langfile = data_path + PDFXOCR_Funcs.OCR_LangArrayW[(int)PDFXOCR_Funcs.PXO_Language.PXO_German] + ".dat";
            if (!System.IO.File.Exists(langfile))
            {
                throw new PDFOCRException($"Fehler: {langfile} existiert nicht !");
            }

            var res = PDFXOCR_Funcs.OCR_Init(out var pdf, dec_key, "");
            if (PDFXOCR_Funcs.IS_DS_FAILED(res))
            {
                throw new PDFOCRException($"OCR Initialisierung fehlgeschlagen");
            }
            do
            {
                //hResult = PDFXOCR.PDFXOCR_Funcs.OCR_SetCallback(pdf, thecallback, 0);
                res = PDFXOCR_Funcs.OCR_LoadW(pdf, par.PDFFilename);
                if (PDFXOCR_Funcs.IS_DS_FAILED(res))
                {
                    throw new PDFOCRException($"Fehler beim Laden der Datei:{par.PDFFilename}");
                };


                PDFXOCR_Funcs.PXO_Options Options = new PDFXOCR_Funcs.PXO_Options
                {
                    blacklist = "",
                    whitelist = "",
                    raster_dpi = 300,
                    ImageFlags = (uint) (PDFXOCR_Funcs.OCR_ImageProcessingFlags.OCR_Content_Original | PDFXOCR_Funcs.OCR_ImageProcessingFlags.OCR_Image_SuppressOutput),
                    DataPath = data_path,
                    lang = PDFXOCR_Funcs.PXO_Language.PXO_German,
                    RegionMode = PDFXOCR_Funcs.OCR_RegionMode.OCR_Auto,
                    SecondLanguage = PDFXOCR_Funcs.PXO_Language.PXO_English
                };
                var pxoPagelist = IntPtr.Zero;
                res = PDFXOCR_Funcs.OCR_MakeSearchable(pdf, ref Options, pxoPagelist);

                if (PDFXOCR_Funcs.IS_DS_FAILED(res))
                {
                    throw new PDFOCRException($"Fehler beim Ausführen der OCR-Erkennung.\nFehlercode: {res}");
                }

                res = PDFXOCR_Funcs.OCR_SaveW(pdf, par.OutputPDFFilename);
                if (PDFXOCR_Funcs.IS_DS_FAILED(res))
                {
                    throw new PDFOCRException($"Fehler beim Speichern PDF-Datei. Fehlercode: {res}");
                }

            } while (false);
            PDFXOCR_Funcs.OCR_Delete(pdf);
            PDFXOCR_Funcs.OCR_Finalize();
        }

Re: OCR_SaveW gives first time 0, all others -2147418113

Posted: Tue Mar 23, 2021 8:05 am
by baumunk
Hello xChange Support,

What about this error?
When can I expect an answer?

With kind regards
Ernest Baumunk

Re: OCR_SaveW gives first time 0, all others -2147418113

Posted: Tue Mar 23, 2021 12:57 pm
by Tracker Supp-Stefan
Hello Ernest,

I have asked my colleagues in the dev team working with the OCR SDK to take a look here and advise!
They will post their feedback and suggestions here soon!

Kind regards,
Stefan

Re: OCR_SaveW gives first time 0, all others -2147418113

Posted: Thu Mar 25, 2021 10:28 am
by baumunk
Hello Stefan,

I think I have solved this.
May function OCR_Finalize only be called once?

OCR_Finalize is not described in your OCRToolsSDK_Help.pdf.

If OCR_Finalize is called only once when closing the application, everything is OK. I can call OCR_SaveW several times.

With kind regards
Ernest Baumunk

Re: OCR_SaveW gives first time 0, all others -2147418113

Posted: Thu Mar 25, 2021 11:23 am
by Sasha - Tracker Dev Team
Hello baumunk,

We've rushed updating the OCR_LoadW method so that OCR_Init(), OCR_Delete() and OCR_Finalize() methods are moved from the cycle.
But, when testing, it seems that without the OCR_Finalize() in cycle, the Instance initialization inside won't be done several times and everything will work as needed.
Basically, you have found an ideal solution of how this can work, because the OCREngine will reinitialize all of the stuff inside when doing work and the Instance won't be recreated several times.

Cheers,
Alex