Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert DWG or DFX to PDF in Java
// Load the source CAD file
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("input.dwg");
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set auto scaling
rasterizationOptions.setAutomaticLayoutsScaling(true);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to PDF
objImage.save("dwg-to-pdf.pdf", pdfOptions);
// Load the source CAD file
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("input.dwg");
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set background and drawing color
rasterizationOptions.setDrawType(CadDrawTypeMode.UseDrawColor);
rasterizationOptions.setBackgroundColor(com.aspose.cad.Color.getBlue());
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to PDF
objImage.save("dwg-to-pdf.pdf", pdfOptions);
// Load the source CAD file
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("input.dwg");
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Load the source CAD file
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("sample.dwg");
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Export CAD to PDF
objImage.save("dwg-to-pdf.pdf", pdfOptions);
// Load the source CAD file
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("input.dwg");
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
ArrayList<String> layers=new ArrayList<String>();
layers.add("LayerA");
// Set background and drawing color
rasterizationOptions.setLayers(layers);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to PDF
objImage.save("dwg-to-pdf.pdf", pdfOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment