CAD (Computer-Aided Design) document formats are designed to work on detailed drawings, building plans, and device diagrams for their subsequent production or related work. What used to be done manually on a drawing board in pase, now can be done quickly on a computer.
The most used formats in the CAD design industry are DWG, DWF, DXF, DGN. In this article, we will discuss how to view CAD files in Java applications.
GroupDocs.Viewer for Java provides API to render CAD documents formats to PNG, PDF, JPEG, and HTML. Also, API includes special options for additional result image processing. Supported formats are DWF, DXF, DGN, IFC, STL, DWT, Plotter documents, and many others.
Follow one of the ways as described in the Installation section to install and reference GroupDocs.Viewer for Java.
How to render CAD files into HTML, JPG, PNG, or PDF
Rendering to HTML with Embedded Resources in Java
To render your file to HTML file(s) with embedded resources do the following steps:
With Viewer class load your document.
With the forEmbeddedResources method create the HtmlViewOptions instance and type output file name.
Call view method to render your document to HTML, resources will be embedded in to file.
CAD files often consist of many layouts and layers. You can obtain information on what layouts and layers are in a specific file with the following code:
With Viewer class load your document.
Сreate ViewInfoOptions instance using ViewInfoOptions.forHtmlView() method.
Call getViewInfo to get layers/layouts information and get CadViewInfo object result.
Layouts and layers Lists are located in resulted CadViewInfo object.
You can use this information to specify what layers/layouts render in the output file.
File type: Design Web Format File (.dwf)Pages count: 3Layouts:
three-layouts-with-layers-Layout1 8.40063667297363x6.40062713623047px
three-layouts-with-layers-Layout2 8.40063667297363x6.40062713623047px
three-layouts-with-layers-Layout3 8.40063667297363x6.40062713623047px
Layers:
CIRCLE (visible)0(visible)TRIANGLE (visible)QUADRANT (visible)
Layers rendering
CAD drawing most often contains multiple layers, drawing contains a list of layers that rendering by default,
but other layers may hidden, because these layers are may contain supervisor remarks, details of the discussion, or
other additional information that should not be in the final drawing.
To render your file with specific layers please do the following steps:
With Viewer class load your document.
Сreate HtmlViewOptions/JpgViewOptions/PngViewOptions/PdfViewOptions instance and type output file name.
Specify layer(s) to render.
Call view method to render your document with specified layers.
This drawing contains two layers: “0” - with a rectangle and “CIRCLE” with a circle. We want to render circle only,
so we added a layer with the name “CIRCLE” in the layers list.
Layouts rendering
By default GroupDocs.Viewer renders CAD file model presentation (document default layer).
If you want to choose a different layout you can set the layout name to render.
To render your file with specific layouts please do the following steps:
With Viewer class load your document.
Сreate HtmlViewOptions/JpgViewOptions/PngViewOptions/PdfViewOptions instance and type output file name.
Set required layout name by calling viewOptions.getCadOptions().setLayoutName() method.
Call view method to render your document with a specified layout.
This drawing contains three layouts: “three-layouts-with-layers-Layout1”, “three-layouts-with-layers-Layout2”, “three-layouts-with-layers-Layout3”.
We select “three-layouts-with-layers-Layout2” layout name with rectangle, we set this layer name in LayoutName property.
Get a Free API License
In order to use the API without evaluation limitations, you can get a free temporary license.
Conclusion
In conclusion, I hope you now know how to view CAD files in Java applications, in this article you have seen how to get models, layers, and layouts information for CAD files in your application.
Also, you can use Online apps to view your files these applications are built based on GroupDocs.Viewer.
You can learn how to use GroupDocs.Viewer in your applications with documentation and if you have any questions or issues you feel free to send these via our forum.