Aspose公司今天发布了Aspose.CAD for Java 1.0版本,该产品是一个新的专门用于处理CAD文件的Java控件,可以处理包含DWG和DXF格式的CAD文件,在发布改产品的后三个月内
Aspose.Imaging产品将逐步删除其中的CAD处理功能,到时候客户如果需要CAD文件处理的功能就只有选择Aspose.CAD for Java了,在这次发布的该产品主要的功能如下:
1.转换CAD文件格式为PDF文件格式
String dataDir = Utils.getDataDir(ConvertDWGFileToPDF.class) + "DWGDrawings/";
String srcFile = dataDir + "Bottom_plate.dwg";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DWG to PDF
image.save(dataDir + "Bottom_plate_out_.pdf", pdfOptions);
2.转换CAD格式文件为光栅图片格式
String dataDir = Utils.getDataDir(ConvertCADDrawingToRasterImageFormat.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Create an instance of PngOptions for the resultant image
ImageOptionsBase options = new PngOptions();
//Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Save resultant image
image.save(dataDir + "conic_pyramid_raster_image_out_.png", options);
3.从CAD文档中删除CAD文件中的各种实体对象
com.aspose.cad.fileformats.cad.CadImage image = (com.aspose.cad.fileformats.cad.CadImage) com.aspose.cad.Image
.load("Input.dwg");
for (int i = 0; i < image.getEntities().length; i++) {
CadBaseEntity baseEntity = image.getEntities()[i];
if (baseEntity.getClass() == com.aspose.cad.fileformats.cad.cadobjects.CadArc.class) {
com.aspose.cad.fileformats.cad.cadobjects.CadArc arc = (com.aspose.cad.fileformats.cad.cadobjects.CadArc)
baseEntity;
if (arc.getCenterPoint().getX() > 1e10) {
// cadImage.RemoveEntityAt(i);
image.removeEntity(baseEntity);
i--;
}
}
}
image.updateSize();
// Create an instance of CadRasterizationOptions and set its various
// properties
com.aspose.cad.imageoptions.CadRasterizationOptions rasterizationOptions = new
com.aspose.cad.imageoptions.CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(com.aspose.cad.Color
.getWhite());
rasterizationOptions.setLayouts(new String[] { "Model" });
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setCenterDrawing(true);
// Create an instance of PdfOptions
com.aspose.cad.imageoptions.PdfOptions pdfOptions = new com.aspose.cad.imageoptions.PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
image.save("Output.pdf", pdfOptions);
该产品的其他功能可以参考该产品的详细介绍。