Add watermark into dwg file

Hello.
I’m trying to add watermark into a dwg drawing.
My code is this:
CadImage cadImage = (CadImage) CadImage.load(filePath);
CadText catText = new CadText();
catText.setDefaultValue(text);
catText.setTextHeight(40);
catText.setFirstAlignment(new Cad3DPoint(300, 40));
catText.setLayerName(“Marca D’agua”);
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(catText);
cadImage.save();
return true;

But it does not work. My intent is to add the watermark and save the file in dwg format passing the output file path. How could I fulfill this?

@rsebastiany,
Hello. I believe your code is fine, let us dig into it better. I created CADJAVA-10798 to test this deeper.

Great. If you don’t find a solution soon, i’ll just save the output file as PDF.

@rsebastiany,
just was going to respond to you. Unfortunately, we are in progress with the implementation of writing to DWG, it is not supported fully. You may write to PDF and as I see it works properly (you may find useful to call cadImage.updateSize() after update of the drawing). Please, consider sending us the file you are trying to put watermark on (if possible), it is not critical for this task but at least we can estimate the complexity of your files and focus on writing some entities further.

@Oleksii.Gorokhovatskyi
Thank you for the reply. Ill try the conversion to pdf.
I have done the dwg to pdf conversion in the past and i had some errors, depending on the input dwg file. I have posted here somewhere about this. Working with dwg files and Aspose has been a pain point in my company, because sometimes it work, and sometimes not. With this simple dwg (attached) i think it will work, but I’m afraid to put it in production because of this pain point I mentioned.EdificioBaraoTriunfo.zip (56.6 KB)

@rsebastiany,
got it, I have added file to the task. We are sorry for the inconvience, feel free to post any issues here, we will investigate and assist you.

@Oleksii.Gorokhovatskyi

The watermark is not visible at the output file, so I believe it did not work properly.
The output file is attached.EdificioBaraoTriunfo.pdf.zip (152.3 KB)

The code I’m using is this:

Boolean aplicarMarcaDaguaDWG(String filePath, String outputFilePath, String text) {
	try {
		CadImage cadImage = (CadImage) CadImage.load(filePath);
		CadText catText = new CadText();
		catText.setDefaultValue(text);
		catText.setTextHeight(40);
		catText.setFirstAlignment(new Cad3DPoint(300, 40));
		catText.setLayerName("Marca D'agua");
		cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(catText);
		cadImage.updateSize();
		CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
		rasterizationOptions.setPageWidth(1600);
		rasterizationOptions.setPageHeight(1600);
		rasterizationOptions.setLayouts(new String[]{"Model"});
		PdfOptions pdfOptions = new PdfOptions();
		pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
		cadImage.save(outputFilePath, pdfOptions);
		return true;
	} catch (Exception e) {
		return false;
	}
}

The watermark was added, but it is so small that is almost invisble! If you search for the watermark text in the pdf file, you will find it. The text is “SOMENTE USO INTERNO” (whitout the quotes). It is located at the bottom of the first floor in the building in this pdf. I’ll try to tweak the code to make the text bigger, in Red font, and in the diagonal aligned horizontally and vertically.

@rsebastiany,
yes, I found it. You may calculate better position and size of the text according to your drawing size.

@Oleksii.Gorokhovatskyi

Hello.

Is it possible to add a 45 degree rotation to the watermark?

@rsebastiany,
Hello, I guess you can apply this:

catText.setTextRotation(45);