需要在 C 语言中从 IronOCR 发布 PDF 文件#

Need to Release PDF File From IronOCR in C#

提问人:Andy 提问时间:5/2/2023 最后编辑:Andy 更新时间:5/2/2023 访问量:175

问:

我正在使用 IronOCR 从使用 C# 放置在文件夹中的 pdf 中提取文本。我正在运行一个进程,该进程等待将 pdf 放入文件夹中,然后运行以下代码。

var ocr = new IronTesseract();
using (var input = new OcrInput(pdfFileToProcess))
{
    input.Deskew();
    input.Binarize();
    var ocrResult = ocr.Read(input);
    textFromOCRResult = ocrResult.Text;
}

示例 pdfFileToProcess 可以是 d:\TestOCR\C01.pdf。

当它运行时,它一次工作得很好。但是,当我将相同或另一个PDF放入该文件夹中时,会出现以下错误。这就像 IronOCR 不会放过 PDF 文件一样。

System.IO.IOException: 'The process cannot access the file 'D:\TestOCR\C01.pdf' because it is being used by another process.'

此错误指向代码行

using (var input = new OcrInput(pdfFileToProcess))
C# 进程 IO OCR

评论

0赞 Anthony G. 5/2/2023
应包含有关 pdfFileToProcess 及其处理方式的详细信息。看起来 IronOcr 中提供的 OcrInput 类有几个构造函数。pdfFileToProcess 是图像吗?字节?由于 OcrInput 实现了 IDisposable(因为您在调用 using 时使用它),因此我怀疑问题是否存在,除非库有一个容易发现的大缺陷。我怀疑问题出在从源代码读取pdfFileToProcess时您自己的代码。您是否在那里使用 using 语句?
0赞 Andy 5/3/2023
@AnthonyG。pdfFileToProcess 是一个指向 PDF 文件的指针,该文件由我的进程在实质上监视文件夹时传递。pdfFileToProcess = Path.GetDirectoryName(枚举器。当前) + “\\” + Path.GetFileName(枚举器.电流);

答: 暂无答案