在水印中工作

在 DWG 中添加水印

有时您希望在图纸上添加一些水印,以指示图纸的目的或是谁创建的。Aspose.CAD for .NET 允许您在 DWG 文件中添加水印。这可以通过创建具有特定文本高度、旋转、样式、调整等的 Text 或 MText 实体来完成,以便提供良好的外观。为此,API 提供了 CadMText 和 CadText 类。

示例代码

下面的代码展示了如何使用 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);
}