Export to PDF with Aspose.CAD for Java

Introduction

Welcome to this comprehensive tutorial on exporting CAD files to PDF using Aspose.CAD for Java. If you’re looking to seamlessly convert your CAD drawings to the widely supported PDF format, you’re in the right place. In this step-by-step guide, we will break down the process, ensuring you understand each step to achieve successful PDF export.

Prerequisites

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

  • Aspose.CAD for Java: Ensure you have the Aspose.CAD library installed in your Java environment. You can download it here.

  • Resource Directory: Set up a directory where your CAD files are stored. Replace “Your Document Directory” in the provided code snippet with the actual path.

Now, let’s move on to the main steps.

Import Namespaces

In your Java project, begin by importing the necessary namespaces to enable the use of Aspose.CAD functionalities.

import com.aspose.cad.Image;
import com.aspose.cad.InterpolationMode;
import com.aspose.cad.SmoothingMode;
import com.aspose.cad.TextRenderingHint;

import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.PdfOptions;
//import com.aspose.cad.imageoptions.TypeOfEntities;

Step 1: Load CAD File

Load your CAD file into the Aspose.CAD Image object. Replace “site.dwf” with your actual CAD file name.

String fileName = (dataDir + "site.dwf");
Image image = Image.load(fileName);

Step 2: Configure PDF Options

Set up the PDF export options, including vector rasterization options such as page height, width, and layouts.

PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);

rasterizationOptions.setPageHeight(500);
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setLayouts(new String[] { "Model" });

Step 3: Export to PDF

Specify the output path for the generated PDF file and save the image with the configured PDF options.

String outPath = dataDir + "site.pdf";
image.save(outPath, pdfOptions);

Congratulations! You have successfully exported your CAD file to a PDF using Aspose.CAD for Java.

Conclusion

In this tutorial, we explored the step-by-step process of exporting CAD files to PDF using Aspose.CAD for Java. By following these simple yet effective steps, you can seamlessly integrate this functionality into your Java applications.

FAQ’s

Q1: Is Aspose.CAD compatible with all CAD file formats?

A1: Yes, Aspose.CAD supports a wide range of CAD formats, ensuring compatibility with various design software.

Q2: Can I customize the PDF output settings?

A2: Absolutely. The tutorial provides a glimpse of the customization options, but you can explore further to tailor the output according to your needs.

Q3: Where can I find additional support for Aspose.CAD?

A3: For any queries or issues, visit the Aspose.CAD forum to seek assistance from the community.

Q4: Is there a free trial available?

A4: Yes, you can access a free trial of Aspose.CAD here.

Q5: How can I obtain a temporary license for Aspose.CAD?

A5: For temporary licensing, visit this link.