OCR_SaveW gives first time 0, all others -2147418113

PDF-X OCR SDK is a New product from us and intended to compliment our existing PDF and Imaging Tools to provide the Developer with an expanding set of professional tools for Optical Character Recognition tasks

Moderators: TrackerSupp-Daniel, Tracker Support, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Tracker Supp-Stefan

Post Reply
baumunk
User
Posts: 35
Joined: Fri Nov 13, 2020 8:47 am

OCR_SaveW gives first time 0, all others -2147418113

Post by baumunk » Thu Mar 18, 2021 2:23 pm

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();
        }

baumunk
User
Posts: 35
Joined: Fri Nov 13, 2020 8:47 am

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

Post by baumunk » Tue Mar 23, 2021 8:05 am

Hello xChange Support,

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

With kind regards
Ernest Baumunk

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14597
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

Post by Tracker Supp-Stefan » Tue Mar 23, 2021 12:57 pm

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

baumunk
User
Posts: 35
Joined: Fri Nov 13, 2020 8:47 am

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

Post by baumunk » Thu Mar 25, 2021 10:28 am

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 5496
Joined: Fri Nov 21, 2014 8:27 am
Contact:

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

Post by Sasha - Tracker Dev Team » Thu Mar 25, 2021 11:23 am

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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply