翻譯|行業資訊|編輯:李顯亮|2019-10-22 10:52:08.240|閱讀 443 次
概述:近期Aspose.CAD for .Net更新至最新版v19.9,新增了三個非常實用的新功能——支持通用文件格式、支持水印、支持OLE對象,接下來,我們通過示例來了解新增功能!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.CAD for .NET是一個獨立的AutoCAD處理API。它提供將DWG,DWF和DXF文件轉換為高質量PDF和光柵圖像的功能。開發人員可以從AutoCAD文件中選擇和轉換特定的布局和圖層,并輕松跟蹤整個文件轉換過程。
近期Aspose.CAD for .Net更新至最新版v19.9,新增了三個非常實用的新功能——支持通用文件格式、支持水印、支持OLE對象,接下來,我們通過示例來了解新增功能!
>>歡迎下載Aspose.CAD for .NET v19.9體驗
致改變世界的程序員——限時購買Aspose系列產品享滿減優惠,更有超值紅包邀您來領!更多活動詳情可哦~
CF2文件是可以由CAD / CAM軟件和硬件設備處理的三維設計。例如,它可以在折疊之前存儲紙板箱的形狀和設計。Aspose.CAD提供設備加載通用文件格式,并將其轉換為其他格式,如PDF。下面的代碼示例演示如何加載通用文件格式的文件并將其轉換為PDF。
  // 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的示例是:
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實現目標。
  //文檔目錄的路徑。
            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的示例是:
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);
            
        }ASPOSE技術交流QQ群(642018183)已開通,各類資源及時分享,歡迎交流討論!
如果您對Aspose有任何需求和疑難,記得掃描下方二維碼告訴我們哦~

本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn