Hi
When trying to watermark dwg file ,getting out of memory error.
This is the stack trace
Exception in thread “main” java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.Arrays.copyOf(Unknown Source)
at com.aspose.cad.system.collections.Generic.List.setCapacity(Unknown Source)
at com.aspose.cad.system.collections.Generic.List.a(Unknown Source)
at com.aspose.cad.system.collections.Generic.List.addItem(Unknown Source)
at com.aspose.cad.internal.gv.bP.d(Unknown Source)
at com.aspose.cad.internal.gv.bP.b(Unknown Source)
at com.aspose.cad.internal.gv.bP.a(Unknown Source)
at com.aspose.cad.internal.gv.bP.f(Unknown Source)
at com.aspose.cad.internal.gv.bP.e(Unknown Source)
at com.aspose.cad.internal.gK.k.d(Unknown Source)
at com.aspose.cad.internal.gK.k.a(Unknown Source)
at com.aspose.cad.internal.gK.k.b(Unknown Source)
at com.aspose.cad.internal.gK.k.a(Unknown Source)
at com.aspose.cad.internal.ig.c.a(Unknown Source)
at com.aspose.cad.internal.ig.a.write(Unknown Source)
at com.aspose.cad.fileformats.cad.CadImage.c(Unknown Source)
at com.aspose.cad.DataStreamSupporter.a(Unknown Source)
at com.aspose.cad.DataStreamSupporter.save(Unknown Source)
at addWatermark.ProcessFile.watermarkTextDWGFile(ProcessFile.java:1522)
at addWatermark.ProcessFile.processFile(ProcessFile.java:283)
at addWatermark.ProcessFile.processFiles(ProcessFile.java:185)
at addWatermark.ProcessFile.main(ProcessFile.java:2041)
This is the code we are using to watermark DWG file
private boolean watermarkTextDWGFile (File dwgFile, String watermarkText, String fileSuffix, String outputDirectory) throws Exception {
boolean watermarkedFile = false;
String fileName = "";
try {
fileName = dwgFile.getName();
String fileNameWithOutExt = FilenameUtils.removeExtension(fileName);
String fileExtension = ".dwg";
String filePath = dwgFile.getPath();
//to apply license
com.aspose.cad.License license = new com.aspose.cad.License();
license.setLicense("Aspose.Total.Java.lic");
CadImage cadImage = (CadImage) Image.load(filePath);
//add new MTEXT
CadMText watermark = new CadMText();
// watermark.setText("Watermark message");
watermark.setText(watermarkText);
watermark.setInitialTextHeight(40);
watermark.setInsertionPoint(new Cad3DPoint(300, 40));
watermark.setLayerName("0");
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(watermark);
cadImage.updateSize();
// or add more simple entity like Text
CadText text = new CadText();
text.setDefaultValue(watermarkText);
text.setTextHeight(40);
text.setFirstAlignment(new Cad3DPoint(300, 40));
text.setLayerName("0") ;
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(text);
cadImage.updateSize();
// export to pdf
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setLayouts(new String[]{"Model"});
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
String watermarkedFilePath = outputDirectory + fileSeparator + fileNameWithOutExt + fileSuffix + fileExtension;
cadImage.save(watermarkedFilePath);
// cadImage.save(dataDir + "WMB25-_M04.DXF");
// cadImage.save(dataDir + "AddWatermark_outdwg.pdf", pdfOptions);
cadImage.save(watermarkedFilePath,pdfOptions);
watermarkedFile = true;
}
catch (Exception ex) {
// logger.error("watermarkTextWordFile ex:", ex);
errlog.error("watermarkTextDWGFile ex:" + ex + ":" + fileName);
}
return watermarkedFile;
}