jvm参数:
-Xmx1500m
测试的文件
oom文件123.docx (5.8 MB)
demo:
Document doc = new Document(“D:\test1\oom文件123.docx”);
doc.save(new FileOutputStream(new File(“D:\qys\需求\test1\oom文件123.pdf”)), SaveFormat.PDF);
jvm参数:
-Xmx1500m
测试的文件
oom文件123.docx (5.8 MB)
demo:
Document doc = new Document(“D:\test1\oom文件123.docx”);
doc.save(new FileOutputStream(new File(“D:\qys\需求\test1\oom文件123.pdf”)), SaveFormat.PDF);
Exception in thread “main” java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.aspose.words.internal.zzeD.memberwiseClone(Unknown Source)
at com.aspose.words.internal.zzeD.zzY8c(Unknown Source)
at com.aspose.words.internal.zzIJ.zzuZ(Unknown Source)
at com.aspose.words.internal.zzIJ.zzYvW(Unknown Source)
at com.aspose.words.internal.zzIJ.zz9U(Unknown Source)
at com.aspose.words.internal.zzYJT.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYJT.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYhu.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYJT.zz9U(Unknown Source)
at com.aspose.words.internal.zzYJT.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYJT.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYhu.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYJT.zz9U(Unknown Source)
at com.aspose.words.internal.zzYJT.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYJT.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYhu.zzZfH(Unknown Source)
at com.aspose.words.internal.zzYJT.zz9U(Unknown Source)
at com.aspose.words.internal.zzZeE.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzZ3F.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzZ3F.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzY9f.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzn2.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzW9F.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYJT.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYhu.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYJT.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYhu.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYJT.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYhu.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYJT.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzZGH.zzXQZ(Unknown Source)
at com.aspose.words.internal.zzYJT.zzXQZ(Unknown Source)
@Lycheng, Word 文档中的页数与渲染为 PDF 所需的内存量不对应。 内存量取决于页面上的对象数量以及这些对象的大小。
您的Word文档有很多EMF图像,这可能会导致额外的内存使用。
您可以尝试使用如下代码来减少内存使用:
String tempFolder = "D:\\TempFolder\\";
LoadOptions loadOptions = new LoadOptions();
loadOptions.setTempFolder(tempFolder);
Document doc = new Document("D:\test1\oom文件123.docx", loadOptions);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setTempFolder(loadOptions.getTempFolder());
saveOptions.setMemoryOptimization(true);
doc.save(new FileOutputStream(new File("D:\\qys\\需求\\test1\\oom文件123.pdf")), saveOptions);
还是会溢出,没有任何效果
@Lycheng, 在装有 OpenJDK 20.0.1 的 Windows 10 上,即使内存限制设置为 -Xmx1300m,我也可以渲染您的 Word 文档。
您能否提供有关发生 OOM 异常的环境的更多详细信息?另外,您使用的 Aspose.Words for Java 的确切版本是什么?
我用的是jdk8,Aspose.Words用的23.9
6页用了1300m这么多内存,还是很耗内存