Aspose.CAD for Java
Gist for 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); | |
// 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); | |
// 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); |
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); | |
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); |
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."); |
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."); |
String dataDir = Utils.getDataDir(IntegrateIGESFormat.class) + "CADConversion/"; | |
String sourceFilePath = dataDir + "figa2.igs"; | |
String outPath = dataDir +"meshes.pdf"; | |
Image igesImage = Image.load(sourceFilePath); | |
PdfOptions pdf = new PdfOptions(); | |
CadRasterizationOptions vectorOptions = new CadRasterizationOptions(); | |
vectorOptions.setPageHeight(1000) ; | |
vectorOptions.setPageWidth(1000); | |
pdf.setVectorRasterizationOptions(vectorOptions); | |
igesImage.save(outPath, pdf); |
String dataDir = Utils.getDataDir(ListLayouts.class) + "CADConversion/"; | |
String sourceFilePath = dataDir + "conic_pyramid.dxf"; | |
Image image = Image.load(sourceFilePath); | |
CadImage cadImage = (CadImage)image; | |
CadLayoutDictionary layouts = cadImage.getLayouts(); | |
for (CadLayout layout : layouts.getValues()) | |
{ | |
System.out.println("Layout " +layout.getLayoutName()); | |
} | |
String dataDir = Utils.getDataDir(MeshSupport.class) + "CADConversion/"; | |
String sourceFilePath = dataDir +"meshes.dwg"; | |
String outPath = dataDir + "meshes.pdf"; | |
CadImage cadImage = (CadImage)Image.load(sourceFilePath); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(1600); | |
rasterizationOptions.setPageHeight(1600); | |
rasterizationOptions.setLayouts( new String[] { "Model" }); | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
cadImage.save(outPath, pdfOptions); | |
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); | |
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(srcFile); | |
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); |
String srcFile = dataDir + "conic_pyramid.dxf"; | |
// Image image = Image.load(srcFile); | |
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.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(dataDir +"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); |
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(dataDir +"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); |
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"); | |
} |
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"); |
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"); |
// The path to the resource directory. | |
String dataDir = Utils.getDataDir(SupportOfLayers.class) + "DWFDrawings/"; | |
String srcFile = dataDir + "for_layers_test.dwf"; | |
String outFile = dataDir + "for_layers_test.jpg"; | |
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 | |
List<String> stringList = new ArrayList<>(Arrays.asList("LayerA")); | |
rasterizationOptions.setLayers(stringList); | |
JpegOptions jpegOptions = new JpegOptions(); | |
jpegOptions.setVectorRasterizationOptions(rasterizationOptions); | |
// Export the DXF to JPG | |
image.save(outFile, jpegOptions); |
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
String SourceDir = Utils.getDataDir_DWFXDrawings(); | |
String OutputDir = Utils.getDataDir_Output(); | |
String filePath = SourceDir + "Tyrannosaurus.dwfx"; | |
Image cadImageDwf = Image.load(filePath); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(cadImageDwf.getSize().getWidth()); | |
rasterizationOptions.setPageHeight(cadImageDwf.getSize().getHeight()); | |
PdfOptions CADf = new PdfOptions(); | |
CADf.setVectorRasterizationOptions(rasterizationOptions); | |
cadImageDwf.save(OutputDir + "OpenDwfxFile_out.pdf", CADf); |
// The path to the resource directory. | |
String dataDir = Utils.getDataDir(AccessingUnderlayFlagsofDWG.class) + "DWGDrawings/"; | |
// Input file name and path | |
String fileName = dataDir + "BlockRefDgn.dwg"; | |
// Load an existing DWG file and convert it into CadImage | |
CadImage image = (CadImage)Image.load(fileName); | |
// Go through each entity inside the DWG file | |
for(CadBaseEntity entity : image.getEntities()) | |
{ | |
// Check if entity is of CadDgnUnderlay type | |
if (entity instanceof CadDgnUnderlay) | |
{ | |
// Access different underlay flags | |
CadUnderlay underlay = (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() & UnderlayFlags.UnderlayIsOn) == UnderlayFlags.UnderlayIsOn); | |
System.out.println((underlay.getFlags() & UnderlayFlags.ClippingIsOn) == UnderlayFlags.ClippingIsOn); | |
System.out.println((underlay.getFlags() & UnderlayFlags.Monochrome) != UnderlayFlags.Monochrome); | |
break; | |
} | |
} | |
// 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.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); |
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"; | |
CadImage cadImage = (CadImage)Image.load(srcFile); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setLayouts(new String[]{"Model"}); | |
rasterizationOptions.setNoScaling(true); | |
// note: preserving some empty borders around part of image is the responsibility of customer | |
// top left point of region to draw | |
Point topLeft = new Point(500, 1000); | |
double width = 3108; | |
double height = 2489; | |
CadVportTableObject newView = new CadVportTableObject(); | |
CadStringParameter cadStringParameter = new CadStringParameter(); | |
cadStringParameter.init("*Active"); | |
newView.setName(cadStringParameter); | |
newView.getCenterPoint().setX(topLeft.getX() + width / 2f); | |
newView.getCenterPoint().setY(topLeft.getY() - height / 2f); | |
newView.getViewHeight().setValue(height);; | |
newView.getViewAspectRatio().setValue(width / height); | |
for (int i = 0; i < cadImage.getViewPorts().size(); i++) | |
{ | |
CadVportTableObject currentView = (CadVportTableObject)(cadImage.getViewPorts().get_Item(i)); | |
if (cadImage.getViewPorts().size() == 1 || currentView.getName().getValue().equalsIgnoreCase("*active")) | |
{ | |
cadImage.getViewPorts().set_Item(i, newView); | |
break; | |
} | |
} | |
// Create an instance of PdfOptions | |
PdfOptions pdfOptions = new PdfOptions(); | |
// Set the VectorRasterizationOptions property | |
pdfOptions.setVectorRasterizationOptions(rasterizationOptions); | |
dataDir = dataDir + "ConvertDWGToPDFBySupplyingCoordinates_out.pdf"; | |
//Export the DWG to PDF | |
cadImage.save(dataDir, pdfOptions); | |
String srcFile = dataDir + "Bottom_plate.dwg"; | |
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(srcFile); | |
// 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+"Saved1.pdf", pdfOptions); | |
pdfOptions.getCorePdfOptions().setCompliance(PdfCompliance.PdfA1b); | |
objImage.save(dataDir+"Saved.pdf", pdfOptions); |
String dataDir = Utils.getDataDir(DWGToDWF.class) + "DWGDrawings/"; | |
String inputFile = dataDir+ "Line.dwg"; | |
String outFile = dataDir+ "Line.dwf"; | |
CadImage cadImage = (CadImage)Image.load(inputFile); | |
cadImage.save(outFile); |
// 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); |
public static void main(String[] args) | |
{ | |
// The path to the resource directory. | |
String dataDir = Utils.getDataDir(ExportDWGToPDFOrRaster.class) + "DWGDrawings/"; | |
String srcFile = dataDir + "Bottom_plate.dwg"; | |
com.aspose.cad.Image objImage = com.aspose.cad.Image.load(srcFile); | |
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; | |
} | |
String dataDir = Utils.getDataDir(ExportOLEObjects.class) + "DWGDrawings/"; | |
String[] files = new String[] { "D ZD junior D10m H2m.dwg", "ZD - Senior D6m H2m45.dwg" }; | |
PngOptions pngOptions = new PngOptions(); | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
pngOptions.setVectorRasterizationOptions(rasterizationOptions); | |
rasterizationOptions.setLayouts(new String[] { "Layout1" }); | |
for(String file : files) | |
{ | |
CadImage cadImage = (CadImage)Image.load(dataDir + file); | |
cadImage.save(dataDir + file + "_out.png", pngOptions); | |
} | |
// 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); |
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 | |
CadStringParameter 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 | |
String srcFile = dataDir + "Drawing11.dwg"; | |
Image image = Image.load(srcFile); | |
CadRasterImageDef cadRasterImageDef = new CadRasterImageDef("road-sign-custom.png", 640, 562); | |
cadRasterImageDef.setObjectHandle("A3B4"); | |
Cad3DPoint insertionPoint = new Cad3DPoint(26.77, 22.35); | |
Cad3DPoint uVector = new Cad3DPoint(0.0061565450840500831, 0); | |
Cad3DPoint vVector = new Cad3DPoint(0, 0.0061565450840500822); | |
CadRasterImage cadRasterImage = new CadRasterImage(cadRasterImageDef, insertionPoint, uVector, vVector); | |
cadRasterImage.setImageDefReference("A3B4"); | |
cadRasterImage.setDisplayFlags((short)7); | |
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.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()); | |
} |
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()); | |
} | |
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 SourceDir = Utils.getDataDir_DWGDrawings(); | |
String dwgPathToFile = SourceDir + "SimpleEntites.dwg"; | |
LoadOptions opts = new LoadOptions(); | |
opts.setSpecifiedEncoding(CodePages.Japanese); | |
opts.setSpecifiedMifEncoding(MifCodePages.Japanese); | |
opts.setRecoverMalformedCifMif(false); | |
CadImage cadImage = (CadImage) Image.load(dwgPathToFile, opts); | |
//do export or something else with cadImage | |
// The path to the resource directory. | |
String dataDir = Utils.getDataDir(ParticularDWGToImage.class) + "DWGDrawings/"; | |
String sourceFilePath = dataDir + "visualization_-_conference_room.dwg"; | |
CadImage cadImage = ((CadImage)(Image.load(sourceFilePath))); | |
CadBaseEntity[] entities = cadImage.getEntities(); | |
List<CadBaseEntity> filteredEntities = new ArrayList<CadBaseEntity>(); | |
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); |
CadImage image = (CadImage)Image.load(dataDir+"Bottom_plate.dwg"); | |
{ | |
for (CadBaseEntity entity : image.getEntities()) | |
{ | |
if (entity instanceof CadUnderlay) | |
{ | |
//XREF entity with metadata | |
Cad3DPoint insertionPoint = ((CadUnderlay) entity).getInsertionPoint(); | |
String path = ((CadUnderlay) entity).getUnderlayPath(); | |
} | |
} | |
} |
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()); | |
} |
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 | |
} | |
public static void searchTextInDWGAutoCADFile() | |
{ | |
//String dataDir="Test_Apsose.CAD\\"; | |
// Load an existing DWG file as CadImage. | |
CadImage cadImage = (CadImage) CadImage.load(dataDir + "sample_file.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()) | |
{ | |
IterateCADNodeEntities(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; | |
} | |
} | |
String file = dataDir + "Multileaders.dwg"; | |
Image image = Image.load(file); | |
// Test | |
CadImage cadImage = (CadImage)image; | |
Assert.areNotEqual(cadImage.getEntities().length, 0); | |
CadMLeader cadMLeader = (CadMLeader)cadImage.getEntities()[2]; | |
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.areEqual(formatType2 >= FileFormat.CadR010 && formatType2 <= FileFormat.CadR2013); | |
long formatType3 = Image.getFileFormat(fileName3); | |
Assert.areEqual(formatType3 >= FileFormat.DwtCadR010 && formatType3 <= FileFormat.DwtCadR2013); | |
long formatType4 = Image.getFileFormat(fileName4); | |
Assert.areEqual(formatType4 >= FileFormat.DXFCadR010 && formatType4 <= FileFormat.DXFCadR2013); |
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 dataDir = Utils.getDataDir(ExportDXFToWMF.class) + "DXFDrawings/"; | |
String srcFile = dataDir + "conic_pyramid.dxf"; | |
String outFile = dataDir + "AddCustomProperties_out.dxf"; | |
CadImage cadImage = (CadImage)Image.load(srcFile); | |
cadImage.getHeader().getCustomProperties().put("CUSTOM_PROPERTY_1", "Custom property test 1"); | |
cadImage.getHeader().getCustomProperties().put("CUSTOM_PROPERTY_2", "Custom property test 2"); | |
cadImage.getHeader().getCustomProperties().put("CUSTOM_PROPERTY_3", "Custom property test 3"); | |
cadImage.save(outFile); |
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(); | |
} |
// For complete examples and data files, please go to https://github.com/aspose-cad/Aspose.CAD-for-Java | |
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.getFailures()) | |
{ | |
System.out.printf("{0}. {1}, {2}", idxError, rr.getRenderCode(), rr.getMessage()); | |
idxError++; | |
} | |
} | |
} |
// 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(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); |
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((dataDir +"example.ifc")); | |
try | |
{ | |
{ | |
CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); | |
rasterizationOptions.setPageWidth(100); | |
rasterizationOptions.setPageHeight(100); | |
WmfOptions wmfOptions = new WmfOptions(); | |
cadImage.save(dataDir+" 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 = ""; | |