Lavorare con il Watermark

Aggiungi Watermark in un DWG

A volte vuoi aggiungere dei watermark ai disegni per indicare a quale scopo servono o chi li ha creati. Aspose.CAD per .NET ti consente di aggiungere un watermark in un file DWG. Questo può essere fatto creando un’entità Text o MText con un’altezza di testo specifica, rotazione, stile, aggiustamenti e altro che dovrebbero essere regolati per dare un buon aspetto. Per questo, l’API fornisce CadMTextCadText classi.

Codice di Esempio

Il codice qui sotto mostra come raggiungere lo stesso obiettivo utilizzando Aspose.CAD per .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);
}