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