CAD applications use DGN files for creating 2D or 3D drawings. Specifically, we can create and save designs for construction projects such as highways, bridges, and buildings in a DGN file. In certain cases, we may need to export drawings from DGN files to PDF documents programmatically. Such conversions allow sharing of drawings in a portable format. In this article, we will learn how to convert a DGN file to a PDF in Java.
The following topics shall be covered in this article:
- Java DGN to PDF Converter – Free Download
- Steps to Convert DGN File to PDF Document
- Convert DGN to PDF Programmatically
- Convert DGN to PDF with Options
Java DGN to PDF Converter – Free Download
For converting a DGN file to a PDF document, we will be using the Aspose.CAD for Java API. It allows the creation, editing, and manipulation of DGN files and several other file formats.
The API provides the Image class which is the base class for all types of drawings. The DgnImage class of the API represents a DGN image. We can set PageWidth and PageHeight properties using the CadRasterizationOptions class. The API provides the PdfOptions class that allows specifying the PDF save options.
Please either download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cad</artifactId>
<version>22.3</version>
</dependency>
How to Convert DGN File to PDF using Java
We can easily export a drawing from a DGN file to a PDF document by following the steps given below:
- Load a DGN drawing file.
- Specify PDF save options.
- Save DGN as a PDF.
The following section describes how to transform these steps into Java code and convert a DGN file to a PDF document.
Convert DGN to PDF Programmatically in Java
We can convert a DGN file to a PDF document by following the steps given below:
- Firstly, load an input DGN file using the Image class.
- After that, create an instance of the PdfOptions class.
- Finally, call Save() method to save it as a PDF. It takes the output PDF file path and PdfOptions as arguments.
The following code sample shows how to convert a DGN file to a PDF document using Java.
Convert DGN to PDF with Options in Java
We can specify PDF save options while converting a DGN file to a PDF document by following the steps given below:
- Firstly, load an input DGN file using the Image class.
- Next, create an instance of the CadRasterizationOptions class.
- Then, specify the page height and width.
- Next, create an instance of the PdfOptions class.
- After that, set the VectorRasterizationOptions property as CadRasterizationOptions.
- Finally, call Save() method to save it as a PDF. It takes the output PDF file path and PdfOptions as arguments.
The following code sample shows how to specify the page height and width while saving a DGN file as a PDF document using Java.
Get Free Temporary License
You can get a free temporary license to try the library without evaluation limitations.
Conclusion
In this article, we have learned how to:
- load an existing DGN drawing file;
- specify page height and width;
- define save options;
- save DGN as a PDF in Java.
Besides converting a DGN to a PDF in Java, you can learn more about Aspose.CAD for Java API using the documentation. In case of any ambiguity, please feel free to contact us on our free support forum.