This basic article covers how to convert DWG to TIFF in Java by providing the details to configure the library and a step-wise procedure to develop this application. The CadRasterizationOptions class allows you to customize the output TIFF image according to your requirements. In this sample to convert the DWG file to TIFF in Java, we have exhibited the page size setting for the output TIFF file.
Steps to Export DWG to TIFF in Java
- Configure the environment to add Aspose.CAD for Java from the repository manager to convert DWG to TIFF
- Access the sample DWG file using an instance of the Image class
- Create an instance of the CadRasterizationOptions class to set the output TIFF page size
- Use the TiffOptions class object to set the rasterization options
- Export the DWG as a TIFF file using the TiffOptions object
In the above steps, we have defined the process to convert DWG file to TIFF in Java, where we will commence by loading the source DWG file from the disk using an instance of the Image class, which will then be followed by using an instance of the TiffOptions class object as an argument with the default settings. To customize the rasterization options of the DWG file, you can use CadRasterizationOptions class instance to customize the output TIFF file.
Code to Export DWG to TIFF in Java
import com.aspose.cad.Image; | |
import com.aspose.cad.License; | |
import com.aspose.cad.fileformats.tiff.enums.TiffExpectedFormat; | |
import com.aspose.cad.imageoptions.CadRasterizationOptions; | |
import com.aspose.cad.imageoptions.TiffOptions; | |
public class DwgToTiff { | |
public static void main(String[] args) throws Exception { // main method to convert DWG to TIFF image using Java | |
String path = "/Users/KnowledgeBase/TestData/"; | |
// Set the license to convert DWG to TIFF file | |
License licDwgtoTif = new License(); | |
licDwgtoTif.setLicense(path + "Total.Family.lic"); | |
// Access the source DWG file from the disk | |
Image dwgImage = Image.load(path + "sample.dwg"); | |
// Instantiate CadRasterizationOptions class object | |
CadRasterizationOptions dwgTiffRasOpts = new CadRasterizationOptions(); | |
// Set the output tiff image page size | |
dwgTiffRasOpts.setPageHeight(450); | |
dwgTiffRasOpts.setPageWidth(450); | |
// Create a TiffOptions class reference | |
TiffOptions tiffOpts = new TiffOptions(TiffExpectedFormat.Default); | |
// Set the VectorRasterizationOptions options | |
tiffOpts.setVectorRasterizationOptions(dwgTiffRasOpts); | |
// Export DWG to TIFF | |
dwgImage.save(path + "Exported.tiff", tiffOpts); | |
} | |
} |
In this example, we have exhibited the process to develop a DWG to TIFF converter software in Java using a simple API interface. The CadRasterizationOptions class object is used to enhance the rasterization process like setting the page size, however, you can configure other optional properties like setting the draw type, draw color, background color, layers, pen options, layouts, and quality.
This crisp tutorial demonstrates the process to convert DWG file to TIFF in Java. If you intend to learn about the process of converting SVG to PDF, refer to the articlea bout how to convert SVG to PDF in Java.