DWG Drawings

Exporting DWG Drawings to PDF

Aspose.CAD for Java API can load AutoCAD drawings in DWG format, and convert it to PDF. This topic explains the usage of Aspose.CAD API to achieve the conversion of DWG to PDF format through simple steps as defined ahead.

DWG File Format

A DWG is a binary file that contains vector image data and metadata. The vector image data provides instructions to the CAD application about how to display the DWG; the metadata may contain a variety of information about the file including location-specific data and also client data. Open Specifications for DWG file format can be found in this PDF

Convert DWG Files to PDF

The following simple steps are required to convert DWG to PDF.

  1. Load the DWG file into an instance of Image.
  2. Create an object of the CadRasterizationOptions class and set the PageHeight & PageWidth properties.
  3. Create an object of the PdfOptions class and set the VectorRasterizationOptions property.
  4. Call the Image.save method and pass the object of PdfOptions as the second parameter.

The code sample below shows how to export DWG Drawings to PDF.

Create Single PDF with Different Layout Sizes

Aspose.CAD for Java allows you to convert the DWG file to a single PDF with different layout sizes. This approach works as follows:

  1. Load a DWG file using the Aspose.CAD.Image.load factory method.
  2. Create an instance of the CadRasterizationOptions class and set the resultant page height and width.
  3. Add required LayoutPageSizes for the CadRasterizationOptions object.
  4. Create an instance of PdfOptions class and set its VectorRasterizationOptions property.
  5. Export the image to PDF using the Image.save method.

The code sample below shows how to create a single PDF with different layouts.

Exporting DWG to PDF/A and PDF/E

The following simple steps are required to convert DWG to PDF.

  1. Load the DWG file into an instance of Image.
  2. Create an object of the CadRasterizationOptions class and set the PageHeight & PageWidth properties.
  3. Create an object of the PdfOptions class and set the VectorRasterizationOptions property.
  4. Call the Image.save method and pass the object of PdfOptions as the second parameter.

The code sample below shows how to export DWG Drawings to PDF.

Supported AutoCAD Primitives

The following AutoCAD primitives are supported.

  • TEXT
  • MTEXT
  • ATTDEF
  • ATTRIB
  • ARC
  • ELLIPSE
  • HATCH
  • LEADER
  • POINT
  • VERTEX 2D
  • VERTEX 3D
  • POLYLINE 2D
  • LWPOLYLINE
  • RAY
  • CIRCLE
  • DIMENSION ORDINATE
  • DIMENSION LINEAR
  • DIMENSION ALIGNED
  • DIMENSION ANG 3Pt
  • DIMENSION ANG 2Ln
  • DIMENSION RADIUS
  • DIMENSION DIAMETER
  • SHAPE
  • SOLID
  • SPLINE
  • MLINE
  • LINE
  • XLINE
  • STYLE
  • DIMSTYLE
  • LTYPE
  • MLINESTYLE
  • LAYER
  • VIEWPORT
  • LAYOUT

Exporting Specific DWG Layout to PDF

This approach works as follows:

  1. Load a DWG file using the Image.load factory method.
  2. Create an instance of the CadRasterizationOptions class and set the resultant page height and width.
  3. Set the Layouts property for the CadRasterizationOptions object.
  4. Create an instance of PdfOptions class and set its VectorRasterizationOptions property.
  5. Export the image to PDF using the Image.save() method.

The code sample below shows how to convert a specific layout of DWG to PDF.

Exporting DWG to Raster or PDF using Fixed Size

Aspose.CAD for Java API can load AutoCAD drawings in DWG format, and convert it to PDF or Raster using fixed size.

The code sample below shows how to implement this feature.

Support for rounded hidden lines when exporting DWG/DXF to BMP and PDF

This approach works as follows:

  1. Load a DWG file using the Aspose.CAD.Image.load factory method.
  2. Create an instance of the CadRasterizationOptions class.
  3. Create an instance of the CadRasterizationOptions class and set the resultant page height and width.
  4. Create an instance of PdfOptions class and set its VectorRasterizationOptions property.
  5. Export the image to PDF using the Image.save() method.

The code sample below shows how to implement this feature.

Support for setting print area for DWG image in exported PDF

Aspose.CAD for Java API can load AutoCAD drawings in DWG format, and convert it to PDF. This topic explains the usage of Aspose.CAD API to achieve the support for setting a print area for DWG image in exported PDF.

The code sample below shows how to implement this feature.

Support for reading XREF metadata for DWG file

  1. Load a DWG file using the Aspose.CAD.Image.load factory method.
  2. Traverse through every image entity.
  3. If the entity is CadUnderlay than XREF entity with metadata.

The code sample below shows how to achieve this feature.

DWG document by specifying coordinates

Aspose.CAD for Java API now provides a feature to render DWG documents by providing coordinates of the width and height of the document.

The code sample below shows how to render a DWG document.

The property CadRasterizationOptions.Layouts is of type string array so you may specify more than one layouts at a time for possible conversion to PDF format. While specifying multiple layouts for the CadRasterizationOptions.Layouts property, the resultant PDF would have multiple pages, where each page represents an individual AutoCAD layout.

List All Layouts

You may list all the layouts present in an AutoCAD drawing using the following code snippet.

Get Block Attribute Value Of External Reference

Aspose.CAD for Java API allows you to get an external reference of a block attribute. Aspose.CAD API exposes the getXRefPathName() property to get the external reference of a block attribute in a CadBlockDictionary collection.

The following code demonstrates how to get an external reference of a block attribute.

Search Text In DWG AutoCAD File

Aspose.CAD for Java API allows you to search text in a DWG AutoCAD file. Aspose.CAD API exposes CadText class that represents text entities in the DWG AutoCAD file. Class CadMText is also included in the Aspose.CAD API because some other entities may also contain text.

The following code demonstrates how to search text in the DWG AutoCAD file.

Search For Text In Specific Layout

Accessing underlay Flags for DWG Format

Aspose.CAD for Java has implemented the underlay flags for DWG format and allows developers to access them. Following is the simple code demonstration.

Support for DWG Entities

Aspose.CAD for Java API can load AutoCAD drawings in DWG format and support different entities to work with.

Support for MLeader Entity

A DWG is a binary file that contains vector image data and metadata. There are different entities in a DWG file. The following section describes an example of working with MLeader entity inside the DWG file.

Support for Exporting DWG Entity to Image

A DWG is a binary file that contains vector image data and metadata. There are different entities in a DWG file. The following section describes an example of exporting a particular DWG entity to the image.

Support for Import Image to DWG File

Aspose.CAD for Java API can load AutoCAD drawings in DWG format and support different entities to work with. A DWG is a binary file that contains vector image data and metadata. There are different entities in a DWG file. The following section describes how can we import images inside the DWG file.

Support for Adding text in DWG

Aspose.CAD for Java API can load AutoCAD drawings in DWG format and support different entities to work with. A DWG is a binary file that contains vector image data and metadata. There are different entities in a DWG file. The following section describes how can we add text inside the DWG file.

Support for Mesh in DWG

Aspose.CAD for Java API can now access the entities supporting mesh which include CadPolyFaceMesh and CadPolygonMesh types. The following example describes how can we access the mesh types.

Convert DWG Drawings to DXF

Aspose.CAD provides the feature to load AutoCAD DWG file and export it to DXF format. DWG to DXF conversion approach works as follows:

  1. Load DWG drawing file using the Image.load factory method.
  2. Export the DWG drawing to DXF using the Image.save() method.

The code sample below shows how to convert a DWG file to a DXF format.

Convert DWG Drawings to SVG

Aspose.CAD API can load AutoCAD drawings in DWG format, and convert it to SVG. This topic explains the usage of Aspose.CAD API to achieve the conversion of DWG to SVG format through simple steps as defined below.

  1. Load the DWG file into an instance of Image.
  2. Create an object of the SvgOptions class and set the required properties.
  3. Export the DWG drawing to SVG using the Image.save() method.

The code sample below shows how to convert a DWG file to SVG format.