Aspose.CAD for .NET是一個獨立的AutoCAD處理API。它提供將DWG,DWF和DXF文件轉換爲高質量PDF和光柵圖像的功能。開發人員能夠從AutoCAD文件中選擇和轉換特定的佈局和圖層,並輕鬆跟蹤整個文件轉換過程。bash
近期Aspose.CAD for .Net更新至最新版v19.9,新增了三個很是實用的新功能——支持通用文件格式、支持水印、支持OLE對象,接下來,咱們經過示例來了解新增功能!佈局
CF2文件是能夠由CAD / CAM軟件和硬件設備處理的三維設計。例如,它能夠在摺疊以前存儲紙板箱的形狀和設計。Aspose.CAD提供設備加載通用文件格式,並將其轉換爲其餘格式,如PDF。下面的代碼示例演示如何加載通用文件格式的文件並將其轉換爲PDF。ui
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_ConvertingCFF();
using (Image image = Image.Load(MyDir + "WineBottle_Die.cf2")) { var options = new PdfOptions(); image.Save(MyDir + "WineBottle_Die_out.pdf",options); }複製代碼
基於Java的示例是:spa
String dataDir = Utils.getDataDir(CFFToPDF.class) + "CFF/"; //源文件的路徑 String sourceFilePath = dataDir+"WineBottle_Die.cf2"; Image image = Image.load(sourceFilePath); { PdfOptions options = new PdfOptions(); image.save(dataDir + "WineBottle_Die_out.pdf",options); }複製代碼
水印可防止任何人使用您的專有圖像或文件。若是添加它們,您將可以保護您的工做,並阻止任何想要使用您的圖像或文件來促進其項目或業務的未經您許可的人。Aspose.CAD容許您在DWG文件中添加水印。這能夠經過建立具備特定文本高度,旋轉度,樣式,調整的Text或MText實體來完成,還應對其進行調整以提供良好的外觀。設計
下面的代碼顯示瞭如何使用Aspose.CAD for .NET實現目標。code
//文檔目錄的路徑。
string MyDir = RunExamples.GetDataDir_DWGDrawings();
using(CadImage cadImage = (CadImage)Image.Load(MyDir + "Drawing11.dwg")) { //添加新的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); // 或添加更簡單的實體,例如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); // 導出爲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); }複製代碼
基於Java的示例是:對象
String dataDir = Utils.getDataDir(AddWatermark.class) + "DWGDrawings/"; ////源文件的路徑 String sourceFilePath = dataDir+"Drawing11.dwg"; CadImage cadImage = (CadImage) Image.load(sourceFilePath); //添加新的MTEXT CadMText watermark = new CadMText(); watermark.setText("Watermark message"); watermark.setInitialTextHeight(40); watermark.setInsertionPoint(new Cad3DPoint(300, 40)); watermark.setLayerName("0"); cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(watermark); // 或添加更簡單的實體,例如Text CadText text = new CadText(); text.setDefaultValue("Watermark text"); text.setTextHeight(40); text.setFirstAlignment(new Cad3DPoint(300, 40)); text.setLayerName("0") ; cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(text); //導出爲pdf CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.setPageWidth(1600); rasterizationOptions.setPageHeight(1600); rasterizationOptions.setLayouts(new String[]{"Model"}); PdfOptions pdfOptions = new PdfOptions(); pdfOptions.setVectorRasterizationOptions(rasterizationOptions); cadImage.save(dataDir + "AddWatermark_out.pdf", pdfOptions);複製代碼
對象連接和嵌入(OLE)是Microsoft Windows的一項功能,它使您能夠將信息從一個應用程序複製或移動到另外一個應用程序,同時又保留了在原始應用程序中編輯信息的能力。Aspose.CAD如今支持從DWG格式導出嵌入式OLE對象。開發
下面的代碼顯示瞭如何使用Aspose.CAD for .NET實現目標。文檔
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir_DWGDrawings();
string[] files = new string[] { "D ZD junior D10m H2m.dwg", "ZD - Senior D6m H2m45.dwg" }; PngOptions pngOptions = new PngOptions { }; CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); pngOptions.VectorRasterizationOptions = rasterizationOptions; rasterizationOptions.Layouts = new string[] { "Layout1" }; foreach (string file in files) { using (CadImage cadImage = (CadImage)Image.Load(MyDir + file)) { cadImage.Save(MyDir + file + "_out.png", pngOptions); } }
基於Java的示例是:get
String dataDir = Utils.getDataDir(ExportOLEObjects.class) + "DWGDrawings/"; String[] files = new String[] { "D ZD junior D10m H2m.dwg", "ZD - Senior D6m H2m45.dwg" }; PngOptions pngOptions = new PngOptions(); CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); pngOptions.setVectorRasterizationOptions(rasterizationOptions); rasterizationOptions.setLayouts(new String[] { "Layout1" }); for(String file : files) { CadImage cadImage = (CadImage)Image.load(dataDir + file); cadImage.save(dataDir + file + "_out.png", pngOptions); }