aspose.cad

aspose.cad 如何指定layout进行转换pdf?请问使用过的么 ?

可以使用Aspose.CAD for .NET或Aspose.CAD for Java API来指定layout进行转换pdf。这个API可以加载DWG格式的AutoCAD绘图,并将其转换为PDF,的大概分为以下几步,github地址我放源码里了:

  1. 使用Aspose.CAD.Image.Load或Aspose.CAD.Image.load工厂方法加载DWG文件。
  2. 创建一个CadRasterizationOptions类的实例,并设置结果页面的高度和宽度。
  3. 为CadRasterizationOptions对象添加所需的LayoutPageSizes。
  4. 创建一个PdfOptions类的实例,并设置其VectorRasterizationOptions属性。
  5. 使用Image.Save或Image.save方法将图像导出为PDF。
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the documents directory.
String MyDir = RunExamples.getDataDir_DWGDrawings();
String sourceFilePath = MyDir + "Bottom_plate.dwg";
try (com.aspose.cad.Image image = com.aspose.cad.Image.load(sourceFilePath))
{
   // Create an instance of CadRasterizationOptions and set its various properties
   CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
   rasterizationOptions.setBackgroundColor(Color.getWhite());
   rasterizationOptions.setPageWidth(1600);
   rasterizationOptions.setPageHeight(1600);
   rasterizationOptions.setLayouts(new String[] { "Model" });
   // Set the Entities type property to Entities3D.
   rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D);
   // Enable the usage of predefined Rendering Configurations
   rasterizationOptions.setNoScaling(DxfDrawingUnits.Unitless);
   // Add the layer name to the list that are excluded from rendering
   rasterizationOptions.getLayers().add("0");
   // Create an instance of PdfOptions
   PdfOptions pdfOptions = new PdfOptions();
   // Set the VectorRasterizationOptions property
   pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
   
   // Export layout to PDF
   String outPath = sourceFilePath + ".pdf";
   image.save(outPath, pdfOptions);
}