DGN to PDF Conversion Guide - Aspose.CAD for Java

Introduction

In the dynamic world of CAD (Computer-Aided Design), efficient conversion of DGN (Design) files to PDF (Portable Document Format) is a crucial requirement. Aspose.CAD for Java emerges as a powerful solution, offering seamless integration and robust capabilities. This step-by-step guide aims to walk you through the process of exporting DGN files to PDF using Aspose.CAD for Java, ensuring a smooth and efficient workflow.

Prerequisites

Before diving into the tutorial, ensure you have the following prerequisites in place:

  • Aspose.CAD for Java Library: Download and install the library from the Aspose.CAD for Java Download page.
  • Java Development Environment: Make sure you have a Java development environment set up on your machine.

Import Packages

Start by importing the necessary packages into your Java project:

Step 1: Import Necessary Packages

In your Java project, import the required packages for Aspose.CAD for Java.

import com.aspose.cad.Image;
import com.aspose.cad.fileformats.cad.CadRasterizationOptions;
import com.aspose.cad.fileformats.cad.cadobjects.DgnImage;
import com.aspose.cad.imageoptions.PdfOptions;
import java.awt.Color;

Step 2: Set File Paths

Define the paths for your input DGN file and the output PDF file.

String dataDir = "Your Document Directory" + "ExportingDGN/";
String fileName = dataDir + "Nikon_D90_Camera.dgn";
String outFile  = dataDir + "Nikon_D90_Camera.pdf";

Step 3: Load DGN Image

Load the DGN image using the Aspose.CAD library.

DgnImage objImage = (DgnImage)Image.load(fileName);

Step 4: Configure PDF Export Options

Set up options for exporting to PDF, including page dimensions, automatic layout scaling, background color, and specific layouts to export.

PdfOptions options = new PdfOptions();
CadRasterizationOptions vectorOptions = new CadRasterizationOptions();
vectorOptions.setPageWidth(1500);
vectorOptions.setPageHeight(1500);
vectorOptions.setAutomaticLayoutsScaling(true);
vectorOptions.setBackgroundColor(Color.getBlack());
vectorOptions.setLayouts(new String[] { "1", "2", "3", "9" }); //only export 4 (1,2,3 and 9) views
options.setVectorRasterizationOptions(vectorOptions);

Step 5: Save PDF File

Save the DGN image as a PDF file with the specified options.

objImage.save(outFile, options);

Repeat these steps for different DGN files, adjusting file paths and options as needed.

Conclusion

With Aspose.CAD for Java, converting DGN files to PDF becomes a straightforward process. This guide equips you with the knowledge to seamlessly integrate the library into your Java projects, facilitating efficient CAD file conversions.

FAQ’s

Q1: Can I use Aspose.CAD for Java with other CAD file formats?

A1: Yes, Aspose.CAD supports various CAD formats, providing versatile functionality beyond DGN to PDF conversion.

Q2: Is a temporary license available for Aspose.CAD for Java?

A2: Yes, you can obtain a temporary license here for testing purposes.

Q3: How can I seek support or ask questions about Aspose.CAD for Java?

A3: Visit the Aspose.CAD forum to connect with the community and seek assistance.

Q4: What layouts can I export when converting DGN to PDF?

A4: You can specify the layouts to export by customizing the setLayouts array in the code.

Q5: Where can I find comprehensive documentation for Aspose.CAD for Java?

A5: Refer to the Aspose.CAD for Java documentation for detailed information.