Convert DWG/DXF CAD File to JPG, PNG, GIF Image with Java

convert CAD DWG DXF to PNG JPG Image

DWG files are used to save digital drawings in the 2D or 3D format, while DXF is the Drawing Exchange Format which is used for compatibility of AutoCAD data with other applications. You can convert DWG or DXF to raster image formats like JPG, PNG, GIF, etc. as per your requirements. In this article, you will be learning the CAD file formats conversion to raster images programmatically using Java. Please refer to the following sections for further details:

DWG/DXF to JPG, PNG, GIF Image Converter – Java API Installation

Aspose.CAD for Java API supports working with DWG, DXF, and many other file formats. You do not need any 3rd party application to create, edit or process these files in your applications. Simply download the JAR file from the Downloads section, or install it with the following Maven configurations:

Repository

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>http://repository.aspose.com/repo/</url>
    </repository>
</repositories>

Dependency

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cad</artifactId>
        <version>20.12</version>        
   </dependency>
</dependencies>

Convert DWG/DXF to JPG Image Programmatically using Java

Please follow the steps below for converting a DWG/DXF file to JPG image format:

  1. Load input CAD file DWG/DXF with Image class.
  2. Create an instance of CadRasterizationOptions class.
  3. Specify page width and height.
  4. Create an instance of JpegOptions for the resultant image.
  5. Convert CAD DWG/DXF file to JPG image.

The following code shows how to convert DWG/DXF file to JPG image programmatically in Java:

Convert DWG/DXF to PNG Image Programmatically with Java

You can convert DWG or DXF file to PNG image with the steps below:

  1. Load input CAD drawing.
  2. Initialize an object of CadRasterizationOptions class.
  3. Set image dimensions for the output file.
  4. Specify PngOptions for the output image.
  5. Convert CAD DWG/DXF file to a PNG image.

The code below explains how to convert CAD Drawing DWG or DXF to PNG image programmatically using Java:

DWG/DXF CAD file to GIF Image Conversion in Java

You can convert CAD drawings like DWG or DXF to GIF image with the following steps:

  1. Load source CAD file in Image class object.
  2. Instantiate CadRasterizationOptions class object.
  3. Initialize GifOptions class object.
  4. Convert CAD DWG DXF file to GIFF image with Save() method.

The following code demonstrates how to convert CAD DWG/DXF drawing to GIF Image programmatically with Java:

Get Free API License

You can request a Free Temporary License for evaluating all the features of the API, without any limitations.

Conclusion

In this article, you have explored how to convert CAD drawings like DWG/DXF files to PNG, JPG, or GIF file formats programmatically using Java. You can further explore the API by visiting the Documentation. Please feel free to contact us at the Free Support Forum in case of any queries.

See Also

Convert STL to PDF or PNG Image Programmatically in Java