Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.CAD for Java
Gist for Aspose.CAD for Java
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// Access the setMeteredKey property and pass public and private keys as parameters
com.aspose.cad.Metered.setMeteredKey("<valid pablic key>", "<valid private key>");
// Get consumed qantity value before accessing API
BigDecimal quantityOld = com.aspose.cad.Metered.getConsumptionQuantity();
System.out.println("Consumption quantity" + quantityOld);
// DO PROCESSING
//com.aspose.cad.fileformats.cad.CadImage image =
// (com.aspose.cad.fileformats.cad.CadImage)com.aspose.cad.Image.load("BlockRefDgn.dwg");
// Get consumed qantity value after accessing API
BigDecimal quantity = com.aspose.cad.Metered.getConsumptionQuantity();
System.out.println("Consumption quantity" + quantity());
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// Create an instance of OCR Metered class
com.aspose.cad.Metered metered = new com.aspose.cad.Metered();
// Access the setMeteredKey property and pass public and private keys as parameters
metered.setMeteredKey("<valid pablic key>", "<valid private key>");
// Get consumed qantity value before accessing API
double quantityOld = com.aspose.cad.Metered.getConsumptionQuantity();
System.out.println("Consumption quantity" + quantityOld);
// DO PROCESSING
//com.aspose.cad.fileformats.cad.CadImage image =
// (com.aspose.cad.fileformats.cad.CadImage)com.aspose.cad.Image.load("BlockRefDgn.dwg");
// Get consumed qantity value after accessing API
double quantity = com.aspose.cad.Metered.getConsumptionQuantity();
System.out.println("Consumption quantity" + quantity());
String dataDir = Utils.getDataDir(AdjustingCADDrawingSizeUsingUnitType.class) + "CADConversion/";
// Path to source file
String sourceFilePath = dataDir + "sample.dwg";
// Load a CAD drawing in an instance of Image
Image image = Image.load(sourceFilePath);
// Create an instance of BmpOptions class
com.aspose.cad.imageoptions.BmpOptions bmpOptions = new com.aspose.cad.imageoptions.BmpOptions();
// Create an instance of CadRasterizationOptions and set its various properties
com.aspose.cad.imageoptions.CadRasterizationOptions cadRasterizationOptions =
new com.aspose.cad.imageoptions.CadRasterizationOptions();
bmpOptions.setVectorRasterizationOptions(cadRasterizationOptions);
// cadRasterizationOptions.setCenterDrawing(true);
// Set the UnitType property
cadRasterizationOptions.setUnitType(com.aspose.cad.imageoptions.UnitType.Centimenter);
// Set the layouts property
cadRasterizationOptions.setLayouts( new String[] { "Model" } );
// Export layout to BMP format
String outPath = sourceFilePath + ".bmp";
image.save(outPath, bmpOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// Path to source file
String sourceFilePath = "sample.dwg";
// Load a CAD drawing in an instance of Image
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("sourceFilePath");
// Create an instance of BmpOptions class
com.aspose.cad.imageoptions.BmpOptions bmpOptions = new com.aspose.cad.imageoptions.BmpOptions();
// Create an instance of CadRasterizationOptions and set its various properties
com.aspose.cad.imageoptions.CadRasterizationOptions cadRasterizationOptions =
new com.aspose.cad.imageoptions.CadRasterizationOptions();
bmpOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setCenterDrawing(true);
// Set the UnitType property
cadRasterizationOptions.setUnitType(com.aspose.cad.imageoptions.UnitType.Centimenter);
// Set the layouts property
cadRasterizationOptions.setLayouts( new String[] { "Model" } );
// Export layout to BMP format
String outPath = sourceFilePath + ".bmp";
objImage.save(outPath, bmpOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// Path to source file
String sourceFilePath = "sample.dwg";
// Load a CAD drawing in an instance of Image
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("sourceFilePath");
// Create an instance of BmpOptions class
com.aspose.cad.imageoptions.BmpOptions bmpOptions = new com.aspose.cad.imageoptions.BmpOptions();
// Create an instance of CadRasterizationOptions and set its various properties
com.aspose.cad.imageoptions.CadRasterizationOptions cadRasterizationOptions =
new com.aspose.cad.imageoptions.CadRasterizationOptions();
bmpOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setCenterDrawing(true);
// Set the layouts property
cadRasterizationOptions.setLayouts( new String[] { "Model" } );
// Export layout to BMP format
String outPath = sourceFilePath + ".bmp";
objImage.save(outPath, bmpOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ConvertAllCADLayersToSeparateImages.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
CadImage image = (CadImage) Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set image width & height
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setPageHeight(500);
// Set the drawing to render at the center of image
rasterizationOptions.setCenterDrawing(true);
// Get the layers in an instance of CadLayersDictionary and iterate over the layers
for (CadLayerTable layer : image.getLayers().getValuesTyped()) {
// Display layer name for tracking
System.out.println("Start with " + layer.getName());
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.getLayers().add(layer.getName());
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
JpegOptions options = new JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.setVectorRasterizationOptions(rasterizationOptions);
// Export each layer to JPEG format
image.save(dataDir + layer.getName() + "_out_.jpg", options);
}
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
CadImage image = (CadImage) Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set image width & height
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setPageHeight(500);
// Set the drawing to render at the center of image
// rasterizationOptions.setCenterDrawing(true);
// Get the layers in an instance of CadLayersDictionary.
// Iterate over the layers
for (String layer : image.getLayers().getLayersNames())
{
// Display layer name for tracking
System.out.println("Start with " +layer);
List<String> stringList = Arrays.asList(layer);
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.setLayers(stringList);
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
JpegOptions options = new JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.setVectorRasterizationOptions(rasterizationOptions);
// Export each layer to JPEG format
image.save(dataDir + layer + "_out_.jpg", options);
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(ConvertCADDrawingToRasterImageFormat.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Create an instance of PngOptions for the resultant image
ImageOptionsBase options = new PngOptions();
//Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Save resultant image
image.save(dataDir + "conic_pyramid_raster_image_out_.png", options);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Create an instance of PngOptions for the resultant image
ImageOptionsBase options = new PngOptions();
//Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Save resultant image
image.save(dataDir + "conic_pyramid_raster_image_out_.png", options);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ConvertCADLayerToRasterImageFormat.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of Image
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set image width & height
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setPageHeight(500);
// Set the drawing to render at the center of image
rasterizationOptions.setCenterDrawing(true);
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.getLayers().add("0"); //Most of the CAD drawings have a layer by name 0, you may specify any name
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
JpegOptions options = new JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.setVectorRasterizationOptions(rasterizationOptions);
// Export each layer to JPEG format
image.save(dataDir + "CADLayersToRasterImageFormats_out_.jpg", options);
// The path to the resource directory.
String dataDir = Utils.getDataDir(ConvertCADLayerToRasterImageFormat.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of Image
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set image width & height
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setPageHeight(500);
// Set the drawing to render at the center of image
// rasterizationOptions.setCenterDrawing(true);
List<String> stringList = new ArrayList<>(Arrays.asList("0"));
// Add the layer name to the CadRasterizationOptions's layer list
rasterizationOptions.setLayers(stringList);
// Create an instance of JpegOptions (or any ImageOptions for raster formats)
JpegOptions options = new JpegOptions();
// Set VectorRasterizationOptions property to the instance of CadRasterizationOptions
options.setVectorRasterizationOptions(rasterizationOptions);
// Export each layer to JPEG format
image.save(dataDir + "CADLayersToRasterImageFormats_out_.jpg", options);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ConvertCADLayoutToRasterImageFormat.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Specify a list of layout names
rasterizationOptions.setLayouts(new String[] {"Model", "Layout1"});
// Create an instance of TiffOptions for the resultant image
ImageOptionsBase options = new TiffOptions(TiffExpectedFormat.Default);
// Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Save resultant image
image.save(dataDir + "conic_pyramid_layoutstorasterimage_out_.tiff", options);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// Set page width & height
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1200);
// Specify a list of layout names
rasterizationOptions.setLayouts(new String[] {"Model", "Layout1"});
// Create an instance of TiffOptions for the resultant image
ImageOptionsBase options = new TiffOptions(TiffExpectedFormat.Default);
// Set rasterization options
options.setVectorRasterizationOptions(rasterizationOptions);
// Save resultant image
image.save(dataDir + "conic_pyramid_layoutstorasterimage_out_.tiff", options);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(EnableTrackingForCADRenderingProcess.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
OutputStream stream = new FileOutputStream(dataDir + "conic_pyramid.pdf");
PdfOptions pdfOptions = new PdfOptions();
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setPageWidth(800);
cadRasterizationOptions.setPageHeight(600);
image.save(stream, pdfOptions);
System.out.println("Tracking enabled successfully for CAD rendering process.");
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
OutputStream stream = new FileOutputStream(dataDir + "conic_pyramid.pdf");
PdfOptions pdfOptions = new PdfOptions();
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setPageWidth(800);
cadRasterizationOptions.setPageHeight(600);
image.save(stream, pdfOptions);
System.out.println("Tracking enabled successfully for CAD rendering process.");
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(PenSupportInExport.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
CadImage cadImage = ((CadImage)(Image.load(srcFile)));
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(cadImage.getWidth() * 100);
rasterizationOptions.setPageHeight(cadImage.getHeight() * 100);
PdfOptions pdfOptions = new PdfOptions();
// Here user can change default start cap and end cap of pens when exporting CadImage object to
// image. It can be using for all image formats: pdf, png, bmp, gif, jpeg2000, jpeg, psd, tiff, wmf.
// If user doesn't use PenOptions, system will use its own default pens (different in defferent places).
PenOptions penOts = new PenOptions();
penOts.setStartCap(LineCap.Flat);
penOts.setEndCap(LineCap.Flat);
//rasterizationOptions.setPenOptions(penOts);
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save((dataDir+"9LHATT-A56_generated.pdf"),pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(ReadingDWT.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
//CadImage cadImage = (CadImage) Image.load(srcFile);
com.aspose.cad.fileformats.cad.CadImage objImage =(CadImage) com.aspose.cad.Image.load("sourceFilePath");
for(Object style : objImage.getStyles())
{
// Set the font name
((com.aspose.cad.fileformats.cad.cadtables.CadStyleTableObject)style).setPrimaryFontName("Arial");
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(SetBackgroundAndDrawingColor.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setBackgroundColor(Color.getBeige());
rasterizationOptions.setDrawType(CadDrawTypeMode.UseDrawColor);
rasterizationOptions.setDrawColor(Color.getBlue());
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to PDF
image.save("result_out_.pdf", pdfOptions);
// Create an instance of TiffOptions
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
tiffOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to TIFF
image.save(dataDir + "result_out_.tiff", tiffOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
// Image image = Image.load(srcFile);
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("sourceFilePath");
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setBackgroundColor(com.aspose.cad.Color.getBeige());
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("result_out_.pdf", pdfOptions);
// Create an instance of TiffOptions
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
tiffOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to TIFF
objImage.save(dataDir + "result_out_.tiff", tiffOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(SetCanvasSizeAndMode.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setScaleMethod(ScaleType.GrowToFit);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to PDF
image.save("result_out_.pdf", pdfOptions);
// Create an instance of TiffOptions
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
tiffOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to TIFF
image.save(dataDir + "result_out_.tiff", tiffOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setAutomaticLayoutsScaling(true);
rasterizationOptions.setNoScaling(true);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to PDF
objImage.save("result_out_.pdf", pdfOptions);
// Create an instance of TiffOptions
TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default);
// Set the VectorRasterizationOptions property
tiffOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export CAD to TIFF
objImage.save(dataDir + "result_out_.tiff", tiffOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(SettingAutoLayoutScaling.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set Auto Layout Scaling
rasterizationOptions.setAutomaticLayoutsScaling(true);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the CAD to PDF
image.save(dataDir + "result_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set Auto Layout Scaling
rasterizationOptions.setAutomaticLayoutsScaling(true);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the CAD to PDF
image.save(dataDir + "result_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(SubstituteFont.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
CadImage cadImage = (CadImage) Image.load(srcFile);
// Iterate over the items of CadStylesDictionary
for (CadStyleTableObject style : cadImage.getStyles().getValuesTyped()) {
// Set the font name
style.setPrimaryFontName("Arial");
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
CadImage cadImage = (CadImage) Image.load(srcFile);
// Iterate over the items of CadStylesDictionary
for(Object style : cadImage.getStyles())
{
// Set the font name
((com.aspose.cad.fileformats.cad.cadtables.CadStyleTableObject)style).setPrimaryFontName("Arial");
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(SubstituteFontOfAParticularStyle.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
CadImage cadImage = (CadImage)Image.load(srcFile);
// Specify the font for one particular style
cadImage.getStyles().get_Item("Roman").setPrimaryFontName("Arial");
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
// Load a CAD drawing in an instance of CadImage
CadImage cadImage = (CadImage)Image.load(srcFile);
// Specify the font for one particular style
((com.aspose.cad.fileformats.cad.cadtables.CadStyleTableObject)cadImage.getStyles().get_Item(0)).setPrimaryFontName("Arial");
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// Input file name and path
String fileName = "BlockRefDgn.dwg";
// Load an existing DWG file and convert it into CadImage
com.aspose.cad.fileformats.cad.CadImage image = (com.aspose.cad.fileformats.cad.CadImage) com.aspose.cad.Image.load(fileName);
// Go through each entity inside the DWG file
for (com.aspose.cad.fileformats.cad.cadobjects.CadBaseEntity entity : image.getEntities())
{
// Check if entity is of CadDgnUnderlay type
if (entity instanceof com.aspose.cad.fileformats.cad.cadobjects.CadDgnUnderlay)
{
// Access different underlay flags
com.aspose.cad.fileformats.cad.cadobjects.CadUnderlay underlay = (com.aspose.cad.fileformats.cad.cadobjects.CadUnderlay) entity;
System.out.println(underlay.getUnderlayPath());
System.out.println(underlay.getUnderlayName());
System.out.println(underlay.getInsertionPoint().getX());
System.out.println(underlay.getInsertionPoint().getY());
System.out.println(underlay.getRotationAngle());
System.out.println(underlay.getScaleX());
System.out.println(underlay.getScaleY());
System.out.println(underlay.getScaleZ());
System.out.println((underlay.getFlags() & com.aspose.cad.fileformats.cad.cadobjects.UnderlayFlags.UnderlayIsOn) == com.aspose.cad.fileformats.cad.cadobjects.UnderlayFlags.UnderlayIsOn);
System.out.println((underlay.getFlags() & com.aspose.cad.fileformats.cad.cadobjects.UnderlayFlags.ClippingIsOn) == com.aspose.cad.fileformats.cad.cadobjects.UnderlayFlags.ClippingIsOn);
System.out.println((underlay.getFlags() & com.aspose.cad.fileformats.cad.cadobjects.UnderlayFlags.Monochrome) != com.aspose.cad.fileformats.cad.cadobjects.UnderlayFlags.Monochrome);
break;
}
}
String dataDir = Utils.getDataDir(AddTextInDWG.class) + "DWGDrawings/";
String dwgPathToFile = dataDir + "SimpleEntites.dwg";
Image image = Image.load(dwgPathToFile);
CadText cadText = new CadText();
cadText.setStyleType("Standard");
cadText.setDefaultValue("Some custom text");
cadText.setColorId(256);
cadText.setLayerName("0");
cadText.getFirstAlignment().setX(47.9);
cadText.getFirstAlignment().setY(5.56);
cadText.setTextHeight(0.8);
cadText.setScaleX(0);
CadImage cadImage = ((CadImage)(image));
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(cadText);
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
// cadRasterizationOptions.setCenterDrawing(true);
cadRasterizationOptions.setPageHeight(1600);
cadRasterizationOptions.setPageWidth(1600);
cadRasterizationOptions.setLayouts(new String[] {"Model"});
image.save(dataDir+"SimpleEntites_generated.dwg.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ConvertDWGFileToPDF.class) + "DWGDrawings/";
String srcFile = dataDir + "Bottom_plate.dwg";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DWG to PDF
image.save(dataDir + "Bottom_plate_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "Bottom_plate.dwg";
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DWG to PDF
objImage.save(dataDir + "Bottom_plate_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "visualization_-_conference_room.dwg";
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("example.dxf");
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(new CadRasterizationOptions());
pdfOptions.setCorePdfOptions(new PdfDocumentOptions());
pdfOptions.getCorePdfOptions().setCompliance(PdfCompliance.PdfA1a);
objImage.save(dataDir, pdfOptions);
pdfOptions.getCorePdfOptions().setCompliance(PdfCompliance.PdfA1b);
objImage.save(dataDir+"Saved.pdf", pdfOptions);
// The path to the resource directory.
String dataDir = Utils.getDataDir(DWGToDXF.class) + "DWGDrawings/";
String inputFile = dataDir+ "Line.dwg";
String outFile = dataDir+ "Line.dxf";
CadImage cadImage = (CadImage)Image.load(inputFile);
cadImage.save(outFile);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
public static void main(String[] args)
{
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportDWGToPDFOrRaster.class) + "DWGDrawings/";
String srcFile = dataDir + "visualization_-_conference_room.dwg";
com.aspose.cad.Image objImage = com.aspose.cad.Image.load("example.dxf");
Boolean currentUnitIsMetric = IsMetric(objImage.getUnitType());
int currentUnitCoefficient = objImage.getUnitType();
if (currentUnitIsMetric)
{
double metersCoeff = 1 / 1000.0;
double scaleFactor = metersCoeff / currentUnitCoefficient;
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth((float)(210 * scaleFactor));
rasterizationOptions.setPageHeight((float)(297 * scaleFactor));
rasterizationOptions.setUnitType(UnitType.Millimeter);
}
else
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth((float)(8.27f / currentUnitCoefficient));
rasterizationOptions.setPageHeight((float)(11.69f / currentUnitCoefficient));
rasterizationOptions.setUnitType(UnitType.Inch);
}
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(new CadRasterizationOptions());
objImage.save(dataDir+"Saved.pdf", pdfOptions);
}
public static Boolean IsMetric(int initial)
{
Boolean isMetric = true;
switch (initial)
{
case UnitType.Inch:
case UnitType.MicroInch:
case UnitType.Mil:
case UnitType.Foot:
case UnitType.Yard:
case UnitType.Mile:
case UnitType.Unitless:
isMetric = false;
}
return isMetric;
}
private Double Coefficient(int unitType)
{
Double coefficient = 1.0;
switch (unitType)
{
case UnitType.Parsec:
coefficient = 3.0857 * 10000000000000000.0;
break;
case UnitType.LightYear:
coefficient = 9.4607 * 1000000000000000.0;
break;
case UnitType.AstronomicalUnit:
coefficient = 1.4960 * 100000000000.0;
break;
case UnitType.Gigameter:
coefficient = 1000000000.0;
break;
case UnitType.Kilometer:
coefficient = 1000.0;
break;
case UnitType.Decameter:
coefficient = 10.0;
break;
case UnitType.Hectometer:
coefficient = 100.0;
break;
case UnitType.Meter:
coefficient = 1.0;
break;
case UnitType.Centimenter:
coefficient = 0.01;
break;
case UnitType.Decimeter:
coefficient = 0.1;
break;
case UnitType.Millimeter:
coefficient = 0.001;
break;
case UnitType.Micrometer:
coefficient = 0.000001;
break;
case UnitType.Nanometer:
coefficient = 0.000000001;
break;
case UnitType.Angstrom:
coefficient = 0.0000000001;
break;
case UnitType.Inch:
coefficient = 1.0;
break;
case UnitType.MicroInch:
coefficient = 0.000001;
break;
case UnitType.Mil:
coefficient = 0.001;
break;
case UnitType.Foot:
coefficient = 12.0;
break;
case UnitType.Yard:
coefficient = 36.0;
break;
case UnitType.Mile:
coefficient = 63360.0;
break;
}
return coefficient;
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportSpecificDWGLayoutToPDF.class) + "DWGDrawings/";
String srcFile = dataDir + "visualization_-_conference_room.dwg";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Specify desired layout name
rasterizationOptions.setLayouts(new String[] {"Layout1"});
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DWG to PDF
image.save(dataDir + "ExportSpecificLayoutToPDF_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "visualization_-_conference_room.dwg";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Specify desired layout name
rasterizationOptions.setLayouts(new String[] {"Layout1"});
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DWG to PDF
image.save(dataDir + "ExportSpecificLayoutToPDF_out_.pdf", pdfOptions);
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportToSVG.class) + "DWGDrawings/";
Image image = Image.load(dataDir + "meshes.dwg");
{
SvgOptions options = new SvgOptions();
options.setColorType(SvgColorMode.Grayscale);
options.setTextAsShapes(true);
image.save(dataDir + "meshes.svg");
}
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(GetBlockAttributeValueOfExternalReference.class) + "DWGDrawings/";
// Load an existing DWG file as CadImage.
CadImage cadImage = (CadImage) Image.load(dataDir + "sample.dwg");
// Access the external path name property
String sXternalRef = cadImage.getBlockEntities().get_Item("*MODEL_SPACE").getXRefPathName();
System.out.println(sXternalRef);
// Load an existing DWG file as CadImage.
CadImage cadImage = (CadImage) Image.load(dataDir + "sample.dwg");
// Access the external path name property
String sXternalRef = cadImage.getBlockEntities().get_Item("*MODEL_SPACE").getXRefPathName().toString();
System.out.println(sXternalRef);
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
CadRasterImageDef cadRasterImageDef = new CadRasterImageDef();
cadRasterImageDef.setObjectHandle("A3B4");
cadRasterImageDef.setFileName("road-sign-custom.png");
CadRasterImage cadRasterImage = new CadRasterImage();
cadRasterImage.setImageDefReference("A3B4");
cadRasterImage.getInsertionPoint().setX(26.77);
cadRasterImage.getInsertionPoint().setY(22.35);
cadRasterImage.setDisplayFlags((short)7);
cadRasterImage.setImageSizeU(640);
cadRasterImage.setImageSizeV(562);
cadRasterImage.getUVector().setX(0.0061565450840500831);
cadRasterImage.getUVector().setY(0);
cadRasterImage.getVVector().setX(0);
cadRasterImage.getVVector().setY(0.0061565450840500822);
cadRasterImage.setClippingState((short)0);
cadRasterImage.getClipBoundaryVertexList().add(new Cad2DPoint(-0.5, 0.5));
cadRasterImage.getClipBoundaryVertexList().add(new Cad2DPoint(639.5, 561.5));
CadImage cadImage = ((CadImage)(image));
cadImage.getBlockEntities().get_Item("*Model_Space").addEntity(cadRasterImage);
CadBaseObject[] objs = cadImage.getObjects();
CadBaseObject[] arr = new CadBaseObject[objs.length + 1];
int ind = 0;
for (CadBaseObject obj : objs)
{
arr[ind] = obj;
ind++;
}
arr[ind] = cadRasterImageDef;
cadImage.setObjects(arr);
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
// cadRasterizationOptions.setCenterDrawing(true);
cadRasterizationOptions.setPageHeight(1600);
cadRasterizationOptions.setPageWidth(1600);
cadRasterizationOptions.setLayouts(new String[] {"Model"});
image.save((srcFile + "_generated.pdf"), pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ListAllLayoutsInAnAutoCADDrawing.class) + "DWGDrawings/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
CadImage cadImage = (CadImage)image;
CadLayoutDictionary layouts = cadImage.getLayouts();
for (CadLayout layout : layouts.getValues()) {
System.out.println("Layout " + layout.getLayoutName());
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
CadImage cadImage = (CadImage)image;
CadLayoutDictionary layouts = cadImage.getLayouts();
for (CadLayout layout : layouts.getValues())
{
System.out.println("Layout " + layout.getLayoutName());
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "meshes.dwg";
// com.aspose.cad. objImage = com.aspose.cad.CImage.load(srcFile);
CadImage cadImage =(CadImage) com.aspose.cad.Image.load(srcFile);
try
{
for (CadBaseEntity entity : cadImage.getEntities())
{
if (entity instanceof CadPolyFaceMesh)
{
CadPolyFaceMesh asFaceMesh= (CadPolyFaceMesh)entity;
if (asFaceMesh != null)
{
System.out.println("Vetexes count: " + asFaceMesh.getMeshMVertexCount());
}
}
else if (entity instanceof CadPolygonMesh)
{
CadPolygonMesh asPolygonMesh= (CadPolygonMesh)entity;
if (asPolygonMesh != null)
{
System.out.println("Vetexes count: " + asPolygonMesh.getMeshMVertexCount());
}
}
}
}
finally
{
cadImage.dispose();
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(ParticularDWGToImage.class) + "DWGDrawings/";
String srcFile = dataDir + "visualization_-_conference_room.dwg";
//String sourceFilePath = ("BaseAltimetria.dwg");
CadImage cadImage = ((CadImage)(Image.load(srcFile)));
CadBaseEntity[] entities = cadImage.getEntities();
List<CadBaseEntity> filteredEntities = new List<CadBaseEntity>() {
@Override
public int size() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean isEmpty() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean contains(Object o) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Iterator<CadBaseEntity> iterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Object[] toArray() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public <T> T[] toArray(T[] a) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean add(CadBaseEntity e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean remove(Object o) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean containsAll(Collection<?> c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean addAll(Collection<? extends CadBaseEntity> c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean addAll(int index, Collection<? extends CadBaseEntity> c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean removeAll(Collection<?> c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean retainAll(Collection<?> c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void clear() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public CadBaseEntity get(int index) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public CadBaseEntity set(int index, CadBaseEntity element) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void add(int index, CadBaseEntity element) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public CadBaseEntity remove(int index) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public int indexOf(Object o) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public int lastIndexOf(Object o) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ListIterator<CadBaseEntity> listIterator() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ListIterator<CadBaseEntity> listIterator(int index) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public List<CadBaseEntity> subList(int fromIndex, int toIndex) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
};
for (CadBaseEntity baseEntity : entities) {
// selection or filtration of entities
if ((baseEntity.getTypeName() == CadEntityTypeName.TEXT)) {
filteredEntities.add(baseEntity);
}
}
CadBaseEntity[] arr = new CadBaseEntity[filteredEntities.size()];
cadImage.setEntities(filteredEntities.toArray(arr));
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set Auto Layout Scaling
rasterizationOptions.setAutomaticLayoutsScaling(true);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
String outFile = (dataDir+"result_out_generated.pdf");
// Export the CAD to PDF
cadImage.save(outFile, pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
CadImage image = (CadImage)Image.load(dataDir);
{
for (CadBaseEntity entity : image.getEntities())
{
if (entity instanceof CadUnderlay)
{
//XREF entity with metadata
Cad3DPoint insertionPoint = ((CadUnderlay) entity).getInsertionPoint();
String path = ((CadUnderlay) entity).getUnderlayPath();
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "visualization_-_conference_room.dwg";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Specify desired layout name
rasterizationOptions.setLayouts(new String[] {"Layout1"});
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DWG to PDF
image.save(dataDir + "ExportSpecificLayoutToPDF_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Load an existing DWG file as CadImage.
CadImage cadImage = (CadImage) CadImage.load(dataDir + "sample_file.dwg");
// get all layout names and link each layout with corresponding block with entities
CadLayoutDictionary layouts = cadImage.getLayouts();
String[] layoutNames = new String[layouts.size()];
int i = 0;
for (com.aspose.cad.fileformats.cad.cadobjects.CadLayout layout : layouts.getValues()) {
layoutNames[i++] = layout.getLayoutName();
System.out.println("Layout " + layout.getLayoutName() + " is found");
// find block, applicable for DWG only
CadBlockTableObject blockTableObjectReference = null;
for (CadBlockTableObject tableObject : cadImage.getBlocksTables()) {
if (String.CASE_INSENSITIVE_ORDER.compare(tableObject.getHardPointerToLayout(), layout.getObjectHandle()) == 0) {
blockTableObjectReference = tableObject;
break;
}
}
// Collection cadBlockEntity.Entities contains information about all entities on specific layout
// if this collection has no elements it means layout is a copy of Model layout and contains the same entities
// Below line of code is for reference
CadBlockEntity cadBlockEntity = cadImage.getBlockEntities().get_Item(blockTableObjectReference.getBlockName());
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
private static final String dataDir = Utils.getDataDir(SearchTextInDWGAutoCADFile.class) + "DWGDrawings/";
public static void main(String[] args) {
// Search Text In DWG AutoCAD File
searchTextInDWGAutoCADFile();
// Search For Text In Specific Layout
searchForTextInSpecificLayout();
}
public static void searchTextInDWGAutoCADFile()
{
String dataDir="Test_Apsose.CAD\\";
// Load an existing DWG file as CadImage.
CadImage cadImage = (CadImage) CadImage.load(dataDir + "sample_file3.dwg");
for (CadBaseEntity entity : cadImage.getEntities())
{
IterateCADNodeEntities(entity);
}
// Search for text in the block section
for (CadBlockEntity blockEntity : cadImage.getBlockEntities().getValues())
{
for (CadBaseEntity entity : blockEntity.getEntities())
{
IterateCADNodeEntities(entity);
}
}
}
//Recursive function to iterate nodes inside nodes
private static void IterateCADNodeEntities(CadBaseEntity obj)
{
switch (obj.getTypeName())
{
case CadEntityTypeName.TEXT:
CadText childObjectText = (CadText) obj;
System.out.println(childObjectText.getDefaultValue());
break;
case CadEntityTypeName.MTEXT:
CadMText childObjectMText = (CadMText) obj;
System.out.println(childObjectMText.getText());
break;
case CadEntityTypeName.INSERT:
CadInsertObject childInsertObject = (CadInsertObject) obj;
for (CadBaseEntity tempobj : childInsertObject.getChildObjects())
{
IterateCADNodes(tempobj);
}
break;
case CadEntityTypeName.ATTDEF:
CadAttDef attDef = (CadAttDef) obj;
System.out.println(attDef.getDefaultString());
break;
case CadEntityTypeName.ATTRIB:
CadAttrib attAttrib = (CadAttrib) obj;
System.out.println(attAttrib.getDefaultText());
break;
}
}
private static void searchForTextInSpecificLayout() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static void IterateCADNodes(CadBaseEntity tempobj) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String file = "file path";
Image image = Image.load(file);
{
// Test
CadImage cadImage = (CadImage)image;
Assert.areNotEqual(cadImage.getEntities().length, 0);
CadMLeader cadMLeader = (CadMLeader)cadImage.getEntities()[0];
Assert.areEqual(cadMLeader.getStyleDescription(), "Standard");
Assert.areEqual(cadMLeader.getLeaderStyleId(), "12E");
Assert.areEqual(cadMLeader.getArrowHeadId1(), "639");
Assert.areEqual(cadMLeader.getLeaderLineTypeID(), "14");
CadMLeaderContextData context = cadMLeader.getContextData();
Assert.areEqual(context.getArrowHeadSize(), 30.0, 0.1);
Assert.areEqual(context.getBasePoint().getX(), 481, 1);
Assert.areEqual(context.getContentScale(), 1.0, 0.01);
Assert.areEqual(context.getDefaultText().getValue(), "This is multileader with huge text\\P{\\H1.5x;6666666666666666666666666666\\P}bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
Assert.areEqual(context.hasMText(), true);
CadMLeaderNode mleaderNode = context.getLeaderNode();
Assert.areEqual(mleaderNode.getLastLeaderLinePoint().getX(), 473, 1);
CadMLeaderLine leaderLine = mleaderNode.getLeaderLine();
Assert.areEqual(leaderLine.getBreakEndPoint().toString(), null);
Assert.areEqual(Integer.toString(leaderLine.getBreakPointIndex().getValue()), Integer.toString(0));
Assert.areEqual(leaderLine.getBreakStartPoint().toString(), null);
Assert.areEqual(Integer.toString(leaderLine.getLeaderLineIndex().getValue()), Integer.toString(0));
Assert.areEqual(Integer.toString(leaderLine.getLeaderPoints().size()), Integer.toString(4));
Assert.areEqual(Integer.toString(mleaderNode.getBranchIndex()), Integer.toString(0));
Assert.areEqual(mleaderNode.getDogLegLength(), 8.0, 0.1);
Assert.areEqual(context.hasMText(), true);
// Assert.IsTrue((context.hasMText()==true , "Invalid Z value");
Assert.areEqual(context.getTextAttachmentType().getValue(), (short)1);
Assert.areEqual(context.getTextBackgroundColor().getValue(), 18);
Assert.areEqual(context.getTextHeight(), 20.0, 0.1);
Assert.areEqual(context.getTextStyleID().getValue(), "11");
Assert.areEqual(context.getTextRotation().getValue(), 0.0, 0.01);
Assert.areEqual(cadMLeader.getArrowHeadId1(), "639");
Assert.areEqual(cadMLeader.getLeaderType(), 1);
Assert.areEqual(cadMLeader.getBlockContentColor(), 0);
Assert.areEqual(cadMLeader.getLeaderLineColor(), 0);
Assert.areEqual(cadMLeader.getTextHeight(), 1.0, 0.01);
String dataDir = Utils.getDataDir(DistinguishDWTAndDWGFormats.class) + "DWTDrawings/";
String fileName2 = dataDir +"Sample.dwg";
String fileName3 = dataDir +"sample.dwt";
String fileName4 = dataDir +"sample.dxf";
long formatType2 = Image.getFileFormat(fileName2);
Assert.IsTrue(formatType2 >= FileFormat.CadR010 && formatType2 <= FileFormat.CadR2013);
long formatType3 = Image.getFileFormat(fileName3);
Assert.IsTrue(formatType3 >= FileFormat.DwtCadR010 && formatType3 <= FileFormat.DwtCadR2013);
long formatType4 = Image.getFileFormat(fileName4);
Assert.IsTrue(formatType4 >= FileFormat.DXFCadR010 && formatType4 <= FileFormat.DXFCadR2013);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
CadImage cadImage =(CadImage) Image.load(srcFile);
List<CadBaseEntity> mtextList = new ArrayList<CadBaseEntity>();
List<CadBaseEntity> attribList = new ArrayList<CadBaseEntity>();
try
{
for (CadBaseEntity entity : cadImage.getEntities())
{
if (entity.getTypeName() == CadEntityTypeName.MTEXT)
{
mtextList.add(entity);
}
if (entity.getTypeName() == CadEntityTypeName.INSERT)
{
for (CadBaseEntity childObject : entity.getChildObjects())
{
if (childObject.getTypeName() == CadEntityTypeName.ATTRIB)
{
attribList.add(childObject);
}
}
}
}
System.out.println("MText Size: "+ mtextList.size());
System.out.println("Attribute Size: "+ attribList.size());
}
finally
{
cadImage.dispose();
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
CadImage cadImage =(CadImage) Image.load(srcFile);
try
{
for (int i=0; i<cadImage.getEntities().length;i++)
{
if (cadImage.getEntities()[i].getTypeName() == CadEntityTypeName.INSERT)
{
CadBlockEntity block =
(CadBlockEntity)cadImage.getBlockEntities().get_Item(((CadInsertObject)cadImage.getEntities()[i]).getName());
for (CadBaseEntity blockChild : block.getEntities())
{
// process entities
}
}
}
}
finally
{
cadImage.dispose();
}
public static class ErrorHandler extends CadRasterizationOptions.CadRenderHandler
{
@Override
public void invoke(CadRenderResult result) {
System.out.println("Tracking results of exporting");
if (result.isRenderComplete())
return;
System.out.println("Have some problems:");
int idxError = 1;
for (RenderResult rr : result.Failures)
{
System.out.printf("{0}. {1}, {2}", idxError, rr.getRenderCode(), rr.getMessage());
idxError++;
}
}
}
// The path to the resource directory.
String dataDir = Utils.getDataDir(EnableTracking.class) + "DXFDrawings/";
Image image = Image.load(dataDir + "conic_pyramid.dxf");
{
OutputStream stream = new FileOutputStream(dataDir + "output_conic_pyramid.pdf");
{
PdfOptions pdfOptions = new PdfOptions();
CadRasterizationOptions cadRasterizationOptions = new CadRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setPageWidth(800);
cadRasterizationOptions.setPageHeight(600);
cadRasterizationOptions.RenderResult = new ErrorHandler();
System.out.println("Exporting to pdf format");
image.save(stream, pdfOptions);
}
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportDXFDrawingToPDF.class) + "DXFDrawings/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_out_.pdf", pdfOptions);
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
IfcImage cadImage = (IfcImage)Image.load(("example.ifc"));
try
{
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
// rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setPageWidth(100);
rasterizationOptions.setPageHeight(100);
WmfOptions wmfOptions = new WmfOptions();
cadImage.save("example.ifc.wmf", wmfOptions);
}
}
finally
{
cadImage.dispose();
}
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_out_.pdf");
}
// The path to the resource directory.
String dataDir = Utils.getDataDir(RenderDXFAsPDF.class) + "DXFDrawings/";
File[] files = new File(dataDir).listFiles();
for (File file : files) {
String extension = GetFileExtension(file);
if(extension == ".dxf"){
// ****************************
// Set new font per document
// ****************************
CadImage cadImage = (CadImage)Image.load(file.getName());
for (Object style : cadImage.getStyles()) {
// Set font name
((com.aspose.cad.fileformats.cad.cadtables.CadStyleTableObject)style).setPrimaryFontName("Broadway");
}
cadImage.save(file.getName() + "_font.dxf");
// ****************************
// Hide all "straight" lines
// ****************************
CadImage cadImageEntity = (CadImage)Image.load(file.getName());
for (CadBaseEntity entity : cadImageEntity.getEntities()) {
// Make lines invisible
if ((entity.getTypeName() == CadEntityTypeName.LINE)) {
entity.setVisible((short)0);
}
}
cadImageEntity.save(file.getName() + "_lines.dxf");
// ****************************
// Manipulations with text
// ****************************
CadImage cadImageText = (CadImage)Image.load(file.getName());
for (CadBaseEntity entity : cadImageText.getEntities()) {
// Make lines invisible
if ((entity.getTypeName() == CadEntityTypeName.TEXT)) {
((CadText)entity).setDefaultValue("New text here!!! :)");
break;
}
}
cadImageText.save(file.getName() + "_text.dxf");
}//If extension = .dxf
}
private static String GetFileExtension(File file) {
String extension = "";
try {
if (file != null && file.exists()) {
String name = file.getName();
extension = name.substring(name.lastIndexOf("."));
}
} catch (Exception e) {
extension = "";
}
return extension;
}
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportSpecificDXFLayoutToPDF.class) + "DXFDrawings\\";
String srcFile = dataDir + "for_layers_test.dwf";
DwfImage image =(DwfImage)Image.load(srcFile);
List<String> layersNames=image.getLayers().getLayersNames();
DwfWhipLayer layer = image.getLayers().getLayerByName("0");
for (DwfWhipLayer lr : image.getLayers())
{
//...
}
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// rasterizationOptions.setCenterDrawing(true);
String[] stringArray = Arrays.copyOf(layersNames.toArray(), layersNames.toArray().length, String[].class);
List<String> stringList = Arrays.asList(stringArray);
// Add desired layers
rasterizationOptions.setLayers(stringList);
JpegOptions jpegOptions = new JpegOptions();
jpegOptions.setVectorRasterizationOptions(rasterizationOptions);
String output = dataDir+"for_layers_test.jpg";
// Export the DXF to Image
image.save(output, jpegOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportSpecificDXFLayoutToPDF.class) + "DXFDrawings/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Specify desired layout name
rasterizationOptions.setLayouts(new String[] {"Model"});
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_layout_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Specify desired layout name
rasterizationOptions.setLayouts(new String[] {"Model"});
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_layout_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
// The path to the resource directory.
String dataDir = Utils.getDataDir(ExportSpecificLayerOfDXFDrawingToPDF.class) + "DXFDrawings/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Add desired layers
rasterizationOptions.getLayers().add("0");
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_layer_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Add desired layers
rasterizationOptions.setLayers(new String[]{"0"});
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_layer_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String srcFile = dataDir + "conic_pyramid.dxf";
Image image = Image.load(srcFile);
// Create an instance of CadRasterizationOptions and set its various properties
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
// Set the VectorRasterizationOptions property
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Export the DXF to PDF
image.save(dataDir + "conic_pyramid_out_.pdf", pdfOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(SaveDXFFiles.class) + "CADConversion/";
String srcFile = dataDir + "conic_pyramid.dxf";
//String dir = GetFileFromDesktop("");
File dirFile = new File(dataDir);
for (final File fileEntry : dirFile.listFiles())
{
if (fileEntry.getAbsolutePath().toLowerCase().endsWith(".dxf"))
{
SaveDxf(fileEntry.getAbsolutePath(), dataDir + fileEntry.getName() + "_updated.dxf");
}
}
// The path to the resource directory.
String dataDir = Utils.getDataDir(RenderDXFAsPDF.class) + "DXFDrawings/";
String inputFile = dataDir + "SLS-CW-CD-CE001-R01_blockClip.dxf";
String outputFile = dataDir + "SLS-CW-CD-CE001-R01_blockClip.pdf";
CadImage cadImage = (CadImage)Image.load(inputFile);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setBackgroundColor(Color.getWhite());
rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
rasterizationOptions.setPageWidth(1200);
rasterizationOptions.setPageHeight(1600);
rasterizationOptions.setBorderX(30);
rasterizationOptions.setBorderY(5);
// rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setLayouts( new String[] { "Model" } );
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(outputFile, pdfOptions);
Raw