我笔记本电脑配置有4GB 的内存 i3的CPU 这样配置的电脑 代码在运行过程中 10页以内的TIF文件转换PDF文件基本都正常,当出现20页以上的时候 PDF文档有就会抛出异常,提示 Not enough memory for this memory Operation。(前提是我的TIF文件是300分辨率的,幅面都是在A3左右,我是把多个的单页的TIF文件转换成一个PDF文件)。
IOcrEngine _ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Professional, false);
// 启动OCR引擎
_ocrEngine.Startup(null, null, null, Path.Combine(Application.StartupPath, "OcrProfessionalRuntime"));
// 创建文档
IOcrDocument _ocrDocument = _ocrEngine.DocumentManager.CreateDocument();
_ocrEngine.LanguageManager.EnableLanguages(new string[] { "zh-Hans", "en" });
// 启用拼写检查系统,并将英文设置为拼写语言
_ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.Native;
_ocrEngine.SpellCheckManager.SpellLanguage = "en";
foreach (string fileName in ArrFilepath)
{
Application.DoEvents();
if (!File.Exists(fileName)) return;
_ocrDocument.Pages.AddPage(fileName, null);
}
Application.DoEvents();
// 识别所有页面
// 注意,我们不需要调用AutoZone,引擎会检查页面是否被分区,若无,则会自动分区
_ocrDocument.Pages.Recognize(null);
PdfDocumentOptions pdfs = _ocrDocument.DocumentWriterInstance.GetOptions(DocumentFormat.Pdf) as PdfDocumentOptions;
pdfs.ImageOverText = true;//图像与文字 双层PDF
pdfs.PageRestriction = DocumentPageRestriction.Relaxed;
switch (this.cbDocumntType.Text)
{
case "PDF": pdfs.DocumentType = PdfDocumentType.Pdf; break;
case "PDF/A": pdfs.DocumentType = PdfDocumentType.PdfA; break;
case "PDF12": pdfs.DocumentType = PdfDocumentType.Pdf12; break;
case "PDF13": pdfs.DocumentType = PdfDocumentType.Pdf13; break;
case "PDF15": pdfs.DocumentType = PdfDocumentType.Pdf15; break;
case "PDF16": pdfs.DocumentType = PdfDocumentType.Pdf16; break;
}
_ocrDocument.DocumentWriterInstance.SetOptions(DocumentFormat.Pdf, pdfs);
_ocrDocument.Save(strSavePDFPath, DocumentFormat.Pdf, null);
Application.DoEvents();
// 释放此文档
_ocrDocument.Dispose();
// 关闭OCR引擎
_ocrEngine.Shutdown();
GC.Collect();
|
|