We are pleased to announce that Aspose.CAD for Java 1.1.0 has been released. The major developments in this release are the ability to search text within the DWG file and support to convert DGN file to PDF & raster image formats. This release also supports to retrieve block attribute values from within a DWG file and its external references.

Search Text in DWG File

Aspose.CAD for Java API allows you to search text in a DWG AutCAD file. Aspose.CAD API exposes CadText class that represents text entities in the DWG AutoCAD file. Class CadMText is also included in the Aspose.CAD API because some other entities may also contain text.

Following is the code demonstration of text search in DWG AutoCAD file.

String sourceFile = "sample.dwg";

// Load an existing DWG file as DgnImage.
com.aspose.cad.fileformats.dgn.DgnImage dgnImage =
                (com.aspose.cad.fileformats.dgn.DgnImage)com.aspose.cad.Image.load(file);

 // search for text in the file
for (com.aspose.cad.fileformats.cad.cadobjects.CadBaseEntity entity : cadImage.getEntities()) 
{
    // please, note: we iterate through CadText entities here, but some other entities
    // may contain text also, e.g. CadMText and others
    if (entity.getClass() == com.aspose.cad.fileformats.cad.cadobjects.CadText.class) 
    {
        com.aspose.cad.fileformats.cad.cadobjects.CadText text = 
                (com.aspose.cad.fileformats.cad.cadobjects.CadText)entity;
        System.out.println(text.getDefaultValue());
    }
}

Exporting DGN AutoCAD Format To PDF

Aspose.CAD for Java API has introduced the functionality to load a DGN AutoCAD file and convert it to PDF format. CadImage class serves the purpose. You need to load an existing DGN file as CadImage. Create an instance of CadRasterizationOptions class and set different properties. Create an instance of PdfOptions class and pass the CadRasterizationOptions instance. Now call the save method of CadImage class instance.

Following is the code demonstration to convert/export DGN to PDF format.

String file = "sample.dgn";
String outFile = "sample.dgn.pdf";

// load an existing DGN file as DgnImage.
com.aspose.cad.fileformats.dgn.DgnImage dgnImage =
                (com.aspose.cad.fileformats.dgn.DgnImage)com.aspose.cad.Image.load(file);


java.io.OutputStream outStream = new java.io.FileOutputStream(outFile);

com.aspose.cad.imageoptions.DgnRasterizationOptions rasterizationOptions = 
        new com.aspose.cad.imageoptions.DgnRasterizationOptions();

// Create an object of CadRasterizationOptions class and define/set different properties
PdfOptions options = new PdfOptions();
rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(300);
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setAutomaticLayoutsScaling(false);

options.setVectorRasterizationOptions(rasterizationOptions);

// Call the save method of the CadImage class object.
cadImage.save(outStream, options);

Exporting DGN AutoCAD Format To Raster Image Format

Aspose.CAD for Java API has introduced the functionality to load a DGN AutoCAD file and convert it to raster image. CadImage class serves the purpose. You need to load an existing DGN file as CadImage. Create an instance of DgnRasterizationOptions class and set different properties. Create an instance of JpegOptions class and pass the DgnRasterizationOptions instance. Now call the save method of CadImage class instance.

Following is the code demonstration to convert/export DGN to JPEG image.

String file = "sample.dgn";
String outFile = "sample.dgn.jpg";

// load an existing DGN file as DgnImage.
com.aspose.cad.fileformats.dgn.DgnImage dgnImage =
                (com.aspose.cad.fileformats.dgn.DgnImage)com.aspose.cad.Image.load(file);

java.io.OutputStream outStream = new java.io.FileOutputStream(outFile);

// Create an object of DgnRasterizationOptions class and define/set different properties
com.aspose.cad.imageoptions.DgnRasterizationOptions rasterizationOptions = 
        new com.aspose.cad.imageoptions.DgnRasterizationOptions();

// Create an object of JpegOptions class as we are converting the DGN to jpeg and assign DgnRasterizationOptions object to it.
JpegOptions options = new JpegOptions();

rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(300);
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setAutomaticLayoutsScaling(false);

options.setVectorRasterizationOptions(rasterizationOptions);

// Call the save method of the CadImage class object.
cadImage.save(outStream, options);

Get Block Attribute Value Of External Reference

Aspose.CAD for Java API allows you to get external reference of a block attribute. Aspose.CAD API exposes getXRefPathName property to get the external reference of a block attribute in a CadBlockDictionary collection.

Following is the code demonstration of getting external reference of a block attribute.

// Path to the document.
String fileName = "sample.dwg";

// Load an existing DWG file as DgnImage.
com.aspose.cad.fileformats.dgn.DgnImage dgnImage =
                (com.aspose.cad.fileformats.dgn.DgnImage)com.aspose.cad.Image.load(file);

// Access the external path name property
String sXternalRef = cadImage.getBlockEntities().get_Item("Drawing1").getXRefPathName();
System.out.println(sXternalRef); 

Enhancements

The following enhancements have been introduced in this release.

  • The process to convert CAD to BMP format has been improved.
  • The process of converting Face3D objects in DXF has been improved.

To view a complete list of new features and to download the latest release, please visit Aspose.CAD for Java 1.1.0 page in downloads section.

Aspose.CAD for Java Resources

The resources, you may need to accomplish your tasks: