tif转双层pdf Java_TIF文件转双层PDF时 内存不足

在使用Java进行TIF到双层PDF转换时,遇到内存不足的问题。当处理20页以上的高分辨率TIF文件(300dpi,A3尺寸)时,代码会抛出异常。通过调整OCR引擎设置,如启用拼写检查,可能加重了内存消耗。解决方法可能包括优化内存管理,如增加Java堆大小或拆分大型TIF文件。
摘要由CSDN通过智能技术生成

我笔记本电脑配置有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();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值