归档.zip (1.3 MB)
问题
CAD转PDF时CPU 100%,内存溢出,最后导致转换失败。
.net 版本和 java 版本都会出现这样的情况;
java版本在Linux环境下执行,CPU 100%、OOM
版本
Aspose.CAD-20.1 for .net
Aspose.CAD-20.1 for java
归档.zip (1.3 MB)
CAD转PDF时CPU 100%,内存溢出,最后导致转换失败。
.net 版本和 java 版本都会出现这样的情况;
java版本在Linux环境下执行,CPU 100%、OOM
Aspose.CAD-20.1 for .net
Aspose.CAD-20.1 for java
CadImage image = (CadImage) Image.load(input);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setNoScaling(true);
rasterizationOptions.setUnitType(UnitType.Inch);
rasterizationOptions.setPageWidth(1024);
rasterizationOptions.setPageHeight(768);
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
image.save(output, pdfOptions);
Window:
系统版本:Win10 64位
CPU:4核
内存:8 G
Linux:
系统版本: Ubuntu 18.04 64位
CPU: 4核
内存: 8 G
实例类型: I/O优化
Thank you for sharing with us. For OOM in Java based application, I suggest you to please consider increasing the Java Heap size and for .NET based application, please try using x64 based Visual Studio application. I hope the issues will be fixed. But still, I have created an issue with ID CADJAVA-637 in our issue tracking system to further investigate it. This thread has been linked with the issue so that you may be notified once the issue will be fixed.
我们尝试过同样的配置,转换一个10M以上的文件都是能够顺利转换的。
这个共享的文件也只有1.7M,但是最后还是会转换失败。
Java Heap 的大小 和 .NET 的建议都有尝试过的,所以才提出了以上的问题
A.首先,我要说的是,在执行困难的数学运算(例如填充)时,aspose库在导出PDF时会占用100%的CPU。
B.我将项目(cadjava-637.zip)附加到您的客户端。
解压缩项目,然后执行
mnv清洁包装
命令
C.之后,您可以尝试将文件导出为Pdf格式。 确保使用-Xms11g选项
我们已经测试了具有16 GB内存的计算机,并为完成渲染的虚拟机分配了11 GB的内存。
cadjava-637.zip (1.3 MB)
pic-cmd.png (8.1 KB)
pic-11g.png (5.1 KB)
D.此外,有一些方法可以减少输出PDF文件并减少导出所花费的时间:
要在保存大DWG时减小输出PDF文件的大小,可以尝试结合以下一些策略:
1.仅导出DWG的选定区域
2.仅导出选定的布局
3.仅导出DWG的重要元素
4.如果您的任务可接受低分辨率,则导出为PDF内的图像
例子1.1。 通过替换活动的ViewPort导出DWG的区域
final CadImage cadImage = (CadImage)Image.load(input);
try {
com.aspose.cad.Point topLeft = new com.aspose.cad.Point(10000, 10000);
double width = 8000;
double height = 6000;
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setNoScaling(true);
CadVportTableObject newView = new CadVportTableObject();
newView.getName().setValue("*Active");
newView.getCenterPoint().setX(topLeft.getX() + width / 2f);
newView.getCenterPoint().setY(topLeft.getY() - height / 2f);
newView.getViewHeight().setValue(height);
newView.getViewAspectRatio().setValue(width / height);
newView.setUseAspectRatio(true);
// search for active viewport and replace it
for (int i = 0; i < cadImage.getViewPorts().size(); i++) {
CadVportTableObject currentView = (CadVportTableObject) (cadImage.getViewPorts().get_Item(i));
if ((currentView.getName().getValue() == null && cadImage.getViewPorts().size() == 1) ||
currentView.getName().getValue().compareToIgnoreCase("*active") == 0) {
cadImage.getViewPorts().set_Item(i, newView);
break;
}
}
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(output, pdfOptions);
}
finally {
cadImage.dispose();
}
例子1.2。 使用setRelativeScale和setRelativePosition导出DWG区域的另一种方法
final CadImage cadImage = (CadImage)Image.load(input);
try {
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setNoScaling(true);
rasterizationOptions.setPageWidth(800);
rasterizationOptions.setPageHeight(600);
rasterizationOptions.setRelativeScale(0.4f);
rasterizationOptions.setRelativePosition(new com.aspose.cad.PointF(10000f, 10000f));
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(output, pdfOptions);
}
finally {
cadImage.dispose();
}
示例2 –仅导出选定的布局,您可以使用rasterizationOptions.setLayouts
final Image image = Image.load(input);
try {
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(800);
rasterizationOptions.setLayouts(new String[]{"Layout1", "Layout2"});
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
image.save(output, pdfOptions);
}
finally {
image.dispose();
}
示例3 –仅导出DWG的重要元素,您可以过滤工程图元素,例如 导出文本仅使用下一个代码
final CadImage cadImage = (CadImage)Image.load(input);
try {
CadBaseEntity[] entities = cadImage.getEntities();
ArrayList<CadBaseEntity> filteredEntities = new ArrayList<CadBaseEntity>();
for (CadBaseEntity baseEntity : entities)
{
if (baseEntity.getTypeName() == CadEntityTypeName.TEXT)
{
filteredEntities.add(baseEntity);
}
}
CadBaseEntity[] entitiesArray = new CadBaseEntity[filteredEntities.size()];
filteredEntities.toArray(entitiesArray);
cadImage.setEntities(entitiesArray);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(800);
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(output, pdfOptions);
}
finally {
cadImage.dispose();
}
示例4 –使用setContentAsBitmap将DWG内容另存为图像
final Image image = Image.load(input);
try {
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(800);
rasterizationOptions.setContentAsBitmap(true);
rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQuality);
rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHint.AntiAliasGridFit);
rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMode.HighQualityBicubic);
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
image.save(output, pdfOptions);
}
finally {
image.dispose();
}
附言 确保您有足够的可用内存来运行示例文件中的代码段。 我有10 Gb以上的可用内存来处理您的数据。 使用-Xmx13000m选项,运行每个代码段都需要10分钟以上的时间。