Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Gist contains code snippets of examples of Aspose.CAD for Java.
// 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());
// 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);
}
// 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
// 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);
// 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
// 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
CadImage image = (CadImage)Image.load("example.dwt");
{
for (CadBaseEntity entity : image.getEntities())
{
// ...
}
}
// 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
// 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
// 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
// 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
// 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
// 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;
}
}
// 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 + "visualization_-_conference_room.dwg";
CadImage cadImage = (CadImage)Image.load(GetFileFromDesktop("example.dxf"));
// Create an instance of PdfOptions
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(new CadRasterizationOptions());
pdfOptions.setCorePdfOptions(new PdfDocumentOptions());
pdfOptions.getCorePdfOptions().setCompliance(PdfCompliance.PdfA1a);
cadImage.save(outPath, pdfOptions);
pdfOptions.getCorePdfOptions().setCompliance(PdfCompliance.PdfA1b);
cadImage.save(outPath, 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";
CadImage cadImage = (CadImage)Image.load(GetFileFromDesktop("example.dxf"));
Boolean currentUnitIsMetric = IsMetric(image.getUnitType());
double currentUnitCoefficient = Coefficient(image.getUnitType());
if (currentUnitIsMetric)
{
double metersCoeff = 1 / 1000.0;
double scaleFactor = metersCoeff / currentUnitCoefficient;
vectorOptions.setPageWidth((float)(210 * scaleFactor));
vectorOptions.setPageHeight((float)(297 * scaleFactor));
vectorOptions.setUnitType(UnitType.Millimeter);
}
else
{
vectorOptions.setPageWidth((float)(8.27f / currentUnitCoefficient));
vectorOptions.setPageHeight((float)(11.69f / currentUnitCoefficient));
vectorOptions.setUnitType(UnitType.Inch);
}
private 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-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);
// 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
CadImage image = (CadImage)Image.load(fileName);
{
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;
}
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(SupportMLeaderEntityForDWGFormat.class) + "DWGDrawings/";
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(), null);
Assert.areEqual(leaderLine.getBreakPointIndex().getValue(), 0);
Assert.areEqual(leaderLine.getBreakStartPoint(), null);
Assert.areEqual(leaderLine.getLeaderLineIndex().getValue(), 0);
Assert.areEqual(leaderLine.getLeaderPoints().size(), 4);
Assert.areEqual(mleaderNode.getBranchIndex(), 0);
Assert.areEqual(mleaderNode.getDogLegLength(), 8.0, 0.1);
Assert.areEqual(context.hasMText(), true);
Assert.areEqual(context.getTextAttachmentType().getValue(), 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);
}
}
}
// 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);
IfcImage cadImage = (IfcImage)Image.load(GetFileFromDesktop("example.ifc"));
try
{
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setPageWidth(100);
rasterizationOptions.setPageHeight(100);
WmfOptions wmfOptions = new WmfOptions();
WmfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save("example.ifc.wmf", wmfOptions);
}
}
finally
{
cadImage.dispose();
}
// 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
// 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
// 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.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
// The path to the resource directory.
String dataDir = Utils.getDataDir(Export3DAutoCADImagesToPDF.class) + "ExportingCAD/";
String srcFile = dataDir + "conic_pyramid.dxf";
Image cadImage = Image.load(srcFile);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(500);
rasterizationOptions.setPageHeight(500);
rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D);
rasterizationOptions.setLayouts(new String[] {"Model"});
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
cadImage.save(dataDir + "Export3DImagestoPDF_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(ExportCADLayoutsToPDF.class) + "ExportingCAD/";
String srcFile = dataDir + "conic_pyramid.dxf";
// Create an instance of CadImage class and load the file.
Image cadImage = Image.load(srcFile);
// Create an instance of CadRasterizationOptions class
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setPageWidth(1600);
rasterizationOptions.setPageHeight(1600);
// Set the Entities type property to Entities3D.
rasterizationOptions.setTypeOfEntities(TypeOfEntities.Entities3D);
rasterizationOptions.setScaleMethod(ScaleType.GrowToFit);
rasterizationOptions.setContentAsBitmap(true);
// Set Layouts
rasterizationOptions.setLayouts(new String[] {"Model"});
// Create an instance of PDF options class
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
// Set Graphics options
rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQuality);
rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHint.AntiAliasGridFit);
rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMode.HighQualityBicubic);
// Export to PDF by calling the Save method
cadImage.save(dataDir + "CADLayoutsToPDF_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(ExportToBMP.class) + "ExportingCAD/";
String fileName = getFileFromDesktop("APFH Floor Plan.dwf");
com.aspose.cad.Image image = com.aspose.cad.Image.load(fileName);
{
BmpOptions bmpOptions = new BmpOptions();
DwfRasterizationOptions cadRasterizationOptions = new DwfRasterizationOptions();
bmpOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setCenterDrawing(true);
cadRasterizationOptions.setPageHeight(500);
cadRasterizationOptions.setPageWidth(500);
cadRasterizationOptions.setLayouts(new String[] { "Model" });
// export
String outPath = fileName + ".bmp";
image.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(ExportToPDF.class) + "ExportingCAD/";
String fileName = getFileFromDesktop("APFH Floor Plan.dwf");
com.aspose.cad.Image image = com.aspose.cad.Image.load(fileName);
{
PdfOptions pdfOptions = new PdfOptions();
DwfRasterizationOptions cadRasterizationOptions = new DwfRasterizationOptions();
pdfOptions.setVectorRasterizationOptions(cadRasterizationOptions);
cadRasterizationOptions.setCenterDrawing(true);
cadRasterizationOptions.setPageHeight(500);
cadRasterizationOptions.setPageWidth(500);
cadRasterizationOptions.setLayouts(new String[] { "Model" });
// export
String outPath = fileName + ".pdf";
image.save(outPath, pdfOptions);
}
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// Input and Output file paths
String fileName = "BlockRefDgn.dwg";
String outPath = "BlockRefDgn.dwg.pdf";
// Create an instance of PdfOptions class as we are exporting the DWG file to PDF format
com.aspose.cad.imageoptions.PdfOptions exportOptions = new com.aspose.cad.imageoptions.PdfOptions();
// Load any existing DWG file as image and convert it to CadImage type
com.aspose.cad.fileformats.cad.CadImage cadImage = (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 baseEntity : cadImage.getEntities())
{
// Check if entity is an image definition
if (baseEntity.getTypeName() == com.aspose.cad.fileformats.cad.cadconsts.CadEntityTypeName.DGNUNDERLAY)
{
com.aspose.cad.fileformats.cad.cadobjects.CadDgnUnderlay dgnFile = (com.aspose.cad.fileformats.cad.cadobjects.CadDgnUnderlay)baseEntity;
// Get external reference to object
System.out.println(dgnFile.getUnderlayPath());
}
}
// Define settings for CadRasterizationOptions object
com.aspose.cad.imageoptions.CadRasterizationOptions vectorRasterizationOptions = new com.aspose.cad.imageoptions.CadRasterizationOptions();
vectorRasterizationOptions.setPageWidth(1600);
vectorRasterizationOptions.setPageHeight(1600);
vectorRasterizationOptions.setCenterDrawing(true);
vectorRasterizationOptions.setLayouts(new String[] { "Model" });
vectorRasterizationOptions.setScaleMethod(com.aspose.cad.fileformats.cad.ScaleType.None);
vectorRasterizationOptions.setBackgroundColor(com.aspose.cad.Color.getBlack());
vectorRasterizationOptions.setDrawType(com.aspose.cad.fileformats.cad.CadDrawTypeMode.UseObjectColor);
// Set Vector Rasterization Options
exportOptions.setVectorRasterizationOptions(vectorRasterizationOptions);
// Export the DWG to PDF by calling Save method
cadImage.save(outPath, exportOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(ExportEmbeddedDGN.class) + "ExportingDGN/";
using (CadImage cadImage = (CadImage)Image.Load(fileName))
{
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.Layouts = new[] { "Model" };
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = rasterizationOptions;
cadImage.Save(outDir + fileName + ".pdf", pdfOptions);
}
}
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
String dataDir = Utils.getDataDir(ExportingDGNAutoCADFormatToPDF.class) + "ExportingDGN/";
// load an existing DGN file as DgnImage.
DgnImage dgnImage = (DgnImage)Image.load(dataDir + "Nikon_D90_Camera.dgn");
DgnRasterizationOptions rasterizationOptions = new DgnRasterizationOptions();
// Create an object of CadRasterizationOptions class and define/set different properties
PdfOptions options = new PdfOptions();
rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(300);
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setAutomaticLayoutsScaling(false);
options.setVectorRasterizationOptions(rasterizationOptions);
OutputStream outStream = new FileOutputStream(dataDir + "ExportDGNToPdf_Out.pdf");
// Call the save method of the DgnImage class object.
dgnImage.save(outStream, options);
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
String dataDir = Utils.getDataDir(ExportingDGNAutoCADFormatToRasterImageFormat.class) + "ExportingDGN/";
// Load an existing DGN file as DgnImage.
DgnImage dgnImage = (DgnImage) Image.load(dataDir + "Nikon_D90_Camera.dgn");
// Create an object of DgnRasterizationOptions class and define/set different properties
DgnRasterizationOptions rasterizationOptions = new DgnRasterizationOptions();
// Create an object of JpegOptions class as we are converting the DGN to JPEG and assign DgnRasterizationOptions object to it.
ImageOptionsBase options = new JpegOptions();
rasterizationOptions.setPageWidth(600);
rasterizationOptions.setPageHeight(400);
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setAutomaticLayoutsScaling(false);
options.setVectorRasterizationOptions(rasterizationOptions);
OutputStream outStream = new FileOutputStream(dataDir + "ExportDGNToRasterImage_Out.jpg");
// Call the save method of the CadImage class object.
dgnImage.save(outStream, options);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(SupportedDGNElements.class) + "ExportingDGN/";
DgnImage dgnImage = (DgnImage)Image.load(file);
{
for (DgnDrawingElementBase element : dgnImage.getElements())
{
switch (element.getMetadata().getType())
{
case DgnElementType.Line:
case DgnElementType.Ellipse:
case DgnElementType.Curve:
case DgnElementType.BSplineCurveHeader:
case DgnElementType.Arc:
case DgnElementType.Shape:
case DgnElementType.PolyLine:
case DgnElementType.TextNode:
case DgnElementType.Text:
case DgnElementType.ComplexShapeHeader:
case DgnElementType.ComplexChainHeader:
{
//previously supported entities, now supported also for 3D
break;
}
case DgnElementType.SolidHeader3D:
case DgnElementType.Cone:
case DgnElementType.CellHeader:
{
//supported 3D entities
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(SupportForDGNV7 .class) + "ExportingDGN/";
DgnImage dgnImage = (DgnImage)Image.load(file);
{
PdfOptions options = new PdfOptions();
CadRasterizationOptions vectorOptions = new CadRasterizationOptions();
vectorOptions.setPageWidth(1500);
vectorOptions.setPageHeight(1500);
vectorOptions.setCenterDrawing(true);
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);
dgnImage.save(outFile, options);
}
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(ExportIFCToPNG.class) + "ExportingIFC/";
String fileName = "example.ifc";
IfcImage cadImage = (IfcImage)Image.load(fileName);
IfcRasterizationOptions rasterizationOptions = new IfcRasterizationOptions();
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setPageWidth(100);
rasterizationOptions.setPageHeight(100);
PngOptions pngOptions = new PngOptions();
pngOptions.setVectorRasterizationOptions(rasterizationOptions);
String outPath = fileName + ".png";
cadImage.Save(outPath, pngOptions);
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java
String dataDir = Utils.getDataDir(ExportSTLToPNG.class) + "ExportingSTL/";
String fileName = "example.stl";
CadImage cadImage = (CadImage)Image.load(fileName);
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
rasterizationOptions.setCenterDrawing(true);
rasterizationOptions.setPageWidth(100);
rasterizationOptions.setPageHeight(100);
PngOptions pngOptions = new PngOptions();
pngOptions.setVectorRasterizationOptions(rasterizationOptions);
String outPath = "galeon.stl.png";
cadImage.save(outPath, pngOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.