Working with Watermark
Add Watermark in a DWG
Sometimes you want to add some watermarks to drawings to indicate what purpose of the drawings or who created them. Aspose.CAD for Java allows you to add a watermark in a DWG file. This can be done through creating a Text or MText entity with a specific text height, rotation, style, adjustments and such should be adjusted as well to give a good look. For this, the API provides CadMText and CadText classes.
Sample Code
The code below shows how to achieve the same goal using Aspose.CAD for Java
String dataDir = Utils.getDataDir(AddWatermark.class) + "DWGDrawings/"; | |
// Path to source file | |
String sourceFilePath = dataDir+"Drawing11.dwg"; | |
CadImage cadImage = (CadImage) Image.load(sourceFilePath); | |
//add new MTEXT | |
CadMText watermark = new CadMText(); | |
watermark.setText("Watermark message"); | |
watermark.setInitialTextHeight(40); | |
watermark.setInsertionPoint(new Cad3DPoint(300, 40)); | |
watermark.setLayerName("0"); | |
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(watermark); | |
// or add more simple entity like Text | |
CadText text = new CadText(); | |
text.setDefaultValue("Watermark text"); | |
text.setTextHeight(40); | |
text.setFirstAlignment(new Cad3DPoint(300, 40)); | |
text.setLayerName("0") ; | |
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(text); | |
// 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); | |
cadImage.save(dataDir + "AddWatermark_out.pdf", pdfOptions); |