การทำงานกับลายน้ำ

เพิ่มลายน้ำใน DWG

บางครั้งคุณต้องการเพิ่มลายน้ำบางอย่างไปยังภาพวาดเพื่อบ่งชี้ว่าวัตถุประสงค์ของภาพวาดคืออะไรหรือใครเป็นผู้สร้างมันขึ้นมา Aspose.CAD สำหรับ .NET ช่วยให้คุณสามารถเพิ่มลายน้ำในไฟล์ DWG ได้ ซึ่งสามารถทำได้โดยการสร้างเอนทิตี Text หรือ MText พร้อมด้วยความสูงของข้อความ, การหมุน, รูปแบบ, การปรับแต่งและอื่น ๆ ที่ควรปรับให้ดูดี สำหรับนี้ API มี CadMText และ CadText คลาส

ตัวอย่างโค้ด

โค้ดด้านล่างแสดงวิธีการบรรลุเป้าหมายเดียวกันโดยใช้ Aspose.CAD สำหรับ .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);
}