ウォーターマークの追加
Contents
[
Hide
]DWGにウォーターマークを追加する
時々、図面にウォーターマークを追加して、図面の目的や作成者を示したいことがあります。Aspose.CAD for .NETを使用すると、DWGファイルにウォーターマークを追加できます。これは、特定のテキストの高さ、回転、スタイル、調整などを指定して、TextまたはMTextエンティティを作成することで実現できます。そのため、APIは CadMText と CadText クラスを提供しています。
サンプルコード
以下のコードは、Aspose.CAD for .NETを使用して同じ目的を達成する方法を示しています。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |