# Render CAD drawings and models as HTML, PDF, and image files Convert CAD files (DWG, DGN, DXF) to HTML, PDF, PNG, or JPEG using the GroupDocs.Viewer Python API. [GroupDocs.Viewer for Python via .NET](https://products.groupdocs.com/viewer/python-net) allows you to render your CAD drawings and 3D models in HTML, PDF, PNG, and JPEG formats. You do not need to use AutoCAD or other CAD software to load and view CAD files within your Python application (web or desktop). Create a [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) class instance to get started with the GroupDocs.Viewer API. Pass a CAD drawing you want to view to the class constructor. You can load the drawing from a file or stream. Call one of the [Viewer.View](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method overloads to convert the drawing to HTML, PDF, or image format. {{< button style="primary" link="https://products.groupdocs.app/viewer/cad" >}} {{< icon "gdoc_person" >}} View CAD files online {{< /button >}} {{< button style="primary" link="https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Python-via-.NET" >}} {{< icon "gdoc_github" >}} View demos and examples on GitHub {{< /button >}} ## Supported CAD file formats GroupDocs.Viewer supports the following CAD and 3D file formats: * [AutoCAD Drawing](https://docs.fileformat.com/cad/dwg/) (.DWG) * [AutoCAD Drawing Template](https://docs.fileformat.com/cad/dwt) (.DWT) * [Design Web Format](https://docs.fileformat.com/cad/dwf/) (.DWF) * [Drawing Exchange Format](https://docs.fileformat.com/cad/dxf) (.DXF) * [AutoCAD Plotter Document](https://docs.fileformat.com/cad/plt) (.PLT) * [MicroStation Design File (V7)](https://docs.fileformat.com/cad/dgn) (.DGN) * [Industry Foundation Classes](https://docs.fileformat.com/cad/ifc) (.IFC) * [Stereolithography File](https://docs.fileformat.com/cad/stl) (.STL) * [Wavefront 3D Object File](https://docs.fileformat.com/3d/obj/) (.OBJ) * [Common File Format](https://docs.fileformat.com/cad/cf2/) (.CF2) * [IGES (Initial Graphics Exchange Specification) Drawing](https://docs.fileformat.com/cad/igs/) (.IGS) * [HPGL (Hewlett-Packard Graphics Language) Plot File](https://docs.fileformat.com/cad/hpgl/) (.HPG) GroupDocs.Viewer can detect the document format automatically based on information in the file header. ## Render CAD drawings as HTML Create an [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions) class instance and pass it to the [Viewer.View](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert a CAD file to HTML. During the conversion, GroupDocs.Viewer creates an [SVG](https://docs.fileformat.com/page-description-language/svg/) image from the CAD drawing and embeds this image in an [HTML](https://docs.fileformat.com/web/html/) document. The `HtmlViewOptions` class properties allow you to control the conversion process. For instance, you can embed all external resources in the generated HTML file, minify the output file, and optimize it for printing. Refer to the following documentation section for details: [Rendering to HTML]({{< ref "viewer/python-net/developer-guide/rendering-documents/rendering-to-html/_index.md" >}}). ### Create an HTML file with embedded resources To save all elements of an HTML page (including text, graphics, and stylesheets) into a single file, call the [HtmlViewOptions.for_embedded_resources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) method and specify the output file name. {{< tabs "example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_cad_to_html(): # Load CAD file with Viewer("sample.dwg") as viewer: # Create an HTML file for the drawing. # Specify the HTML file name. viewOptions = HtmlViewOptions.for_embedded_resources("render_cad_to_html/pdf_page_{0}.html") viewer.view(viewOptions) if __name__ == "__main__": render_cad_to_html() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "pdf_page_1.html" >}} ```text Page-1
}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_cad_to_html_external(): # Load CAD file with Viewer("sample.dwg") as viewer: # Create an HTML file for the drawing. # Specify the HTML file name and location of external resources. # {0} is replaced with the resource name. viewOptions = HtmlViewOptions.for_external_resources("render_cad_to_html_external/pdf_page_{0}.html", "render_cad_to_html_external/pdf_page_{0}/resource_{0}_{1}", "render_cad_to_html_external/pdf_page_{0}/resource_{0}_{1}") viewer.view(viewOptions) if __name__ == "__main__": render_cad_to_html_external() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-cad-to-html-external-outputs.zip" >}} ```text render_cad_to_html_external/pdf_page_1.html (410 bytes) render_cad_to_html_external/pdf_page_1/resource_1_g.svg (7 KB) render_cad_to_html_external/pdf_page_1/resource_1_s.css (529 bytes) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_cad_to_html_external/render-cad-to-html-external-outputs.zip) {{< /tab >}} {{< /tabs >}} The image below demonstrates the result. External resources are placed in a separate folder. ![Place HTML resources in a separate folder](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-cad-documents/render-to-html-external-resources.png) ## Render CAD drawings as PDF Create a [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert a CAD file to PDF. The `PdfViewOptions` class properties allow you to control the conversion process. For instance, you can protect the output PDF file, reorder its pages, and specify the quality of document images. Refer to the following documentation section for details: [Rendering to PDF]({{< ref "viewer/python-net/developer-guide/rendering-documents/rendering-to-pdf/_index.md" >}}). {{< tabs "example3">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions def render_cad_to_pdf(): # Load CAD file with Viewer("sample.dwg") as viewer: # Create a PDF file for the drawing. # Specify the PDF file name. viewOptions = PdfViewOptions("render_cad_to_pdf/cad_drawing.pdf") viewer.view(viewOptions) if __name__ == "__main__": render_cad_to_pdf() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "cad_drawing.pdf" >}} ```text Binary file (PDF, 3 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_cad_to_pdf/cad_drawing.pdf) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Render a CAD file to PDF](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-cad-documents/render-cad-to-pdf.png) ## Render CAD drawings as PNG Create a [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert a CAD file to PNG. Use the [PngViewOptions.height](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/#properties) and [PngViewOptions.width](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/#properties) properties to specify the output image size in pixels. {{< tabs "example4">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PngViewOptions def render_cad_to_png(): # Load CAD file with Viewer("sample.dwg") as viewer: # Create a PNG image for the drawing. viewOptions = PngViewOptions("render_cad_to_png/cad_page_0.png") # Set width and height. viewOptions.width = 1500 viewOptions.height = 1000 viewer.view(viewOptions) if __name__ == "__main__": render_cad_to_png() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "cad_page_0.png" >}} ```text Binary file (PNG, 44 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_cad_to_png/cad_page_0.png) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Render a CAD file to PNG](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-cad-documents/render-cad-to-png-image.png) ## Render CAD drawings as JPEG Create a [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions) class instance and pass it to the [Viewer.view](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method to convert a CAD file to JPEG. Use the [JpgViewOptions.height](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/#properties) and [JpgViewOptions.width](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/#properties) properties to specify the output image size in pixels. {{< tabs "example5">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import JpgViewOptions def render_cad_to_jpg(): # Load CAD file with Viewer("sample.dwg") as viewer: # Create a JPG image for the drawing. viewOptions = JpgViewOptions("render_cad_to_jpg/cad_to_jpg.jpg") # Set width and height. viewOptions.width = 1500 viewOptions.height = 1000 viewer.view(viewOptions) if __name__ == "__main__": render_cad_to_jpg() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "cad_to_jpg.jpg" >}} ```text Binary file (JPG, 53 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_cad_to_jpg/cad_to_jpg.jpg) {{< /tab >}} {{< /tabs >}} ## Get information about existing layouts and layers Follow the steps below to obtain information about layouts and layers contained in a CAD drawing. You can use this information to specify which layers and layouts to display in the output file. 1. Create a [ViewInfoOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/viewinfooptions) instance for a specific view. 2. Call the [Viewer.get_view_info](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method. {{< tabs "example6">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import ViewInfoOptions def get_cad_info(): # Load CAD file with Viewer("sample.dwg") as viewer: viewInfoOptions = ViewInfoOptions.for_html_view() cad_info = viewer.get_view_info(viewInfoOptions) # Display information about the CAD file. print("File type:", cad_info.file_type) print("Pages count:", len(cad_info.pages)) print("\nView info retrieved successfully.") if __name__ == "__main__": get_cad_info() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "get-cad-info.txt" >}} ```text File type: AutoCAD Drawing Database File (.dwg) Pages count: 1 View info retrieved successfully. ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/get_cad_info/get-cad-info.txt) {{< /tab >}} {{< /tabs >}} The following image shows a sample console output: ![Get information about a CAD file](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-cad-documents/retrieve-cad-file-information.png) ## Render all or specific layouts When you convert a CAD drawing to HTML, PDF, or image format, GroupDocs.Viewer renders only the model-space layout (*Model*). If you also need to render all paper space layouts contained in your CAD file, enable the [CadOptions.render_layouts](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/cadoptions/#properties) option for one of the following classes (depending on the output file format): * [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions) * [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) * [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions) * [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions) Each layout is rendered on a separate page. The following example renders all layouts when converting a CAD drawing to PDF: {{< tabs "example7">}} {{< tab "Python">}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions def render_all_layouts(): # Load CAD file with Viewer("sample.dwg") as viewer: # Convert the document to PDF. options = PdfViewOptions("render_all_layouts/all_layouts.pdf") # Render the Model and all non-empty paper space layouts. options.cad_options.render_layouts = True viewer.view(options) if __name__ == "__main__": render_all_layouts() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "all_layouts.pdf" >}} ```text Binary file (PDF, 26 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_all_layouts/all_layouts.pdf) {{< /tab >}} {{< /tabs >}} To render a specific layout, assign the layout name to the [CadOptions.layout_name](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/cadoptions/#properties) property of a target view. {{< tabs "example8">}} {{< tab "Python">}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions def render_specific_layout(): # Load CAD file with Viewer("sample.dwg") as viewer: # Convert the document to PDF. options = PdfViewOptions("render_specific_layout/specific_layout.pdf") # Specify the name of the layout to render. # If the specified layout is not found, # an exception occurs. options.cad_options.layout_name = "layout1" viewer.view(options) if __name__ == "__main__": render_specific_layout() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "specific_layout.pdf" >}} ```text Binary file (PDF, 3 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_specific_layout/specific_layout.pdf) {{< /tab >}} {{< /tabs >}} {{< alert style="info" >}} 1. The [CadOptions.RenderLayouts](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/cadoptions/#properties) and [CadOptions.layout_name](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/cadoptions/#properties) properties apply only to the following file formats: DWG, DWT, DXF, and DWF. 2. If you use the [CadOptions.layout_name](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/cadoptions/#properties) property to render a specific layout, the [CadOptions.render_layouts](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/cadoptions/#properties) option is ignored.{{< /alert >}} ## Render specific layers A CAD drawing can contain many layers. Each layer is used to draw a specific object type. For example, the drawing below contains layers for walls, furniture, plants, and so on. You can control the visibility of objects on the drawing by turning specific layers on or off. ![Layers in a CAD file](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-cad-documents/autocad-drawing-layers.png) When you convert a CAD drawing to HTML, PDF, or image format, GroupDocs.Viewer renders all available layers. You can specify which layers to display in the output file, as described below: 1. Access the [CadOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/baseviewoptions/#properties) property for a target view: * [HtmlViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions) * [PdfViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions) * [PngViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions) * [JpgViewOptions](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions) 2. Assign the list of layers you want to render to the [cad_options.layers](https://reference.groupdocs.com/viewer/net/groupdocs.viewer.options/cadoptions/#properties) property. The following example renders layers with walls and furniture to PDF: {{< tabs "example9">}} {{< tab "Python">}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions from groupdocs.viewer.results import Layer def render_specific_layers(): # Load CAD file with Viewer("sample.dwg") as viewer: # Convert the document to PDF. options = PdfViewOptions("render_specific_layers/specific_layers.pdf") # Specify a list of layers to display. options.cad_options.layers = [ Layer("QUADRANT") ] viewer.view(options) if __name__ == "__main__": render_specific_layers() ``` {{< /tab >}} {{< tab "sample.dwg" >}} {{< tab-text >}} `sample.dwg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-cad-documents/sample.dwg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "specific_layers.pdf" >}} ```text Binary file (PDF, 2 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-cad-documents/render-cad-documents/render_specific_layers/specific_layers.pdf) {{< /tab >}} {{< /tabs >}} The image below illustrates the result. ![Render specific CAD layers](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-cad-documents/render-specific-layers.png)