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 .NET 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 .NET
// The path to the documents directory. | |
string MyDir = RunExamples.GetDataDir_DWGDrawings(); | |
using(CadImage cadImage = (CadImage)Image.Load(MyDir + "Drawing11.dwg")) { | |
//add new MTEXT | |
CadMText watermark = new CadMText(); | |
watermark.Text = "Watermark message"; | |
watermark.InitialTextHeight = 40; | |
watermark.InsertionPoint = new Cad3DPoint(300, 40); | |
watermark.LayerName = "0"; | |
cadImage.BlockEntities["*Model_Space"].AddEntity(watermark); | |
// or add more simple entity like Text | |
CadText text = new CadText(); | |
text.DefaultValue = "Watermark text"; | |
text.TextHeight = 40; | |
text.FirstAlignment = new Cad3DPoint(300, 40); | |
text.LayerName = "0"; | |
cadImage.BlockEntities["*Model_Space"].AddEntity(text); | |
// export to pdf | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.PageWidth = 1600; | |
rasterizationOptions.PageHeight = 1600; | |
rasterizationOptions.Layouts = new[] { "Model" }; | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.VectorRasterizationOptions = rasterizationOptions; | |
cadImage.Save(MyDir + "AddWatermark_out.pdf", pdfOptions); | |
} | |