워터마크 작업

DWG에 워터마크 추가하기

때로는 도면에 워터마크를 추가하여 도면의 목적 또는 작성자를 나타내고 싶습니다. Aspose.CAD for .NET을 사용하면 DWG 파일에 워터마크를 추가할 수 있습니다. 이는 특정 텍스트 높이, 회전, 스타일, 조정 등을 갖춘 텍스트 또는 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);
}