public static void Run() { //ExStart:AddTextInDWG string MyDir = RunExamples.GetDataDir_DWGDrawings(); string dwgPathToFile = MyDir + "SimpleEntites.dwg"; using (Image image = Image.Load(dwgPathToFile)) { CadText cadText = new CadText(); cadText.StyleType = "Standard"; cadText.DefaultValue = "Some custom text"; cadText.ColorId = 256; cadText.LayerName = "0"; cadText.FirstAlignment.X = 47.90; cadText.FirstAlignment.Y = 5.56; cadText.TextHeight = 0.8; cadText.ScaleX = 0.0; CadImage cadImage = (CadImage)image; cadImage.BlockEntities["*Model_Space"].AddEntity(cadText); PdfOptions pdfOptions = new PdfOptions(); CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions(); pdfOptions.VectorRasterizationOptions = cadRasterizationOptions; cadRasterizationOptions.DrawType = CadDrawTypeMode.UseObjectColor; //cadRasterizationOptions.CenterDrawing = true; cadRasterizationOptions.PageHeight = 1600; cadRasterizationOptions.PageWidth = 1600; cadRasterizationOptions.Layouts = new string[] { "Model" }; image.Save(MyDir + "SimpleEntites_generated.pdf", pdfOptions); } //ExEnd:AddTextInDWG }
private static void IterateCADNodes(CadBaseEntity obj) { switch (obj.TypeName) { case CadEntityTypeName.TEXT: CadText childObjectText = (CadText)obj; Console.WriteLine(childObjectText.DefaultValue); break; case CadEntityTypeName.MTEXT: CadMText childObjectMText = (CadMText)obj; Console.WriteLine(childObjectMText.Text); break; case CadEntityTypeName.INSERT: CadInsertObject childInsertObject = (CadInsertObject)obj; foreach (var tempobj in childInsertObject.ChildObjects) { IterateCADNodes(tempobj); } break; case CadEntityTypeName.ATTDEF: CadAttDef attDef = (CadAttDef)obj; Console.WriteLine(attDef.DefaultString); break; case CadEntityTypeName.ATTRIB: CadAttrib attAttrib = (CadAttrib)obj; Console.WriteLine(attAttrib.DefaultText); break; } }
public static void Run() { //ExStart:AddWatermark // 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); } //ExEnd:AddWatermark }