# GroupDocs.Viewer for Python via .NET — Complete Documentation > Native Python library that renders 190+ file formats — DOCX, PDF, XLSX, PPTX, CAD, email, archives, images — to HTML, PDF, PNG, or JPG on Windows, Linux, and macOS. No Microsoft Office or Adobe Acrobat required. --- ## Features Overview Path: https://docs.groupdocs.com/viewer/python-net/getting-started/features-overview/ ## Rendering Documents The term *rendering* in GroupDocs.Viewer describes the process of converting a document into a file format that preserves page boundaries. For example, when a three-page DOCX file is rendered to HTML, the result is three HTML files — one per page. See the [Developer Guide]({{< ref "viewer/python-net/developer-guide/rendering-documents/_index.md" >}}) for runnable examples. ![Rendering diagram](https://docs.groupdocs.com/viewer/python-net/images/getting-started/features-overview/rendering.png) ### Rendering to HTML Rendering to HTML is the best choice when you need to: - Build a web-based application and display document content inside a browser. - Allow users to interact with the rendered text — select, copy, or search it. - View document pages separately. - Zoom in on a document without quality loss. - Rotate, reorder, or watermark pages. GroupDocs.Viewer for Python offers two HTML resource-management modes: - **HTML with external resources** — stores page resources (CSS, fonts, images) next to the HTML file so common resources are reused across pages. Reduces overall page size and speeds up loading. - **HTML with embedded resources** — inlines every resource into the HTML file so each page is self-contained. Larger individual files but easier to distribute. ### Rendering to PNG or JPEG Rendering to PNG or JPEG is the best choice when you need to: - Support any type of application (desktop, web, mobile, CLI). - Restrict interaction with rendered text — for example, to prevent copying. You can still extract a text layer separately if you want to overlay selectable text on the image. - View document pages separately. - Rotate, reorder, or watermark pages. A quick comparison of the two image formats: - **PNG** is a lossless raster format that supports full-colour images and transparency. PNG does not expose a quality setting. It is a good choice for line drawings, text, and iconic graphics at small file sizes. - **JPEG** is a lossy compressed format whose quality can be tuned — lowering the quality removes detail and adds noise, but the file becomes smaller. JPEG is optimal for photographs and any image with a large colour range, and is a common web choice thanks to its compression ratio. ### Rendering to PDF GroupDocs.Viewer renders a document into a single PDF file. Rendering to PDF is the best choice when you need to: - Print documents. - Send documents via email. - Distribute all pages as a single file rather than a collection of per-page files. ## Retrieving Document Information GroupDocs.Viewer for Python exposes basic information about a source document — file type, page count, text with coordinates, and more — without rendering. See [Get Document Info]({{< ref "viewer/python-net/developer-guide/get-document-info" >}}). Format-specific information is also available: - **Archive** — list of folders contained in the archive. - **CAD** — list of layers and layouts in a CAD document. - **Email** — list of folders contained in an Outlook data file. - **PDF** — a flag that indicates whether document printing is allowed. - **Project Management** — project start and end dates. ### Text extraction You can opt to extract document text when rendering to PNG or JPEG. The text is returned together with per-word coordinates, which is helpful when overlaying a selectable text layer on a page image. ## Processing Attachments In GroupDocs.Viewer, *attachments* covers email attachments, files embedded in PDFs, and individual items inside compressed archives. With GroupDocs.Viewer you can list and save: - Email attachments. - Files embedded in PDF documents. - Email messages contained in Outlook and Lotus Notes data files. - Individual files inside archive containers. See [Processing Attachments]({{< ref "viewer/python-net/developer-guide/processing-attachments" >}}) for a runnable example. ## Output Transformation GroupDocs.Viewer for Python ships a set of options to transform each rendered page: - **Rotate pages** — change page orientation when rendering to HTML, JPG, PNG, or PDF. - **Add a text watermark** — stamp a text watermark on every rendered page. - **Reorder pages** — render pages in any order you prefer, including when rendering to PDF. ## Caching Results GroupDocs.Viewer for Python supports caching to accelerate repeat renderings and reduce overall load on the application. By default, the cache is stored on the local disk. The viewer API also exposes cache interfaces that can be implemented for third-party storage — FTP, Amazon S3, Dropbox, Google Drive, Microsoft Azure, Redis, or any other backend. --- ## Load document from local disk Path: https://docs.groupdocs.com/viewer/python-net/developer-guide/loading-documents/load-document-from-local-disk/ You can load a document from a local disk using a path to a file. GroupDocs.Viewer opens the file in the read-only mode. The following code snippet shows how to load a document using the local path string: {{< tabs "example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def load_document_from_local_disk(): # Load document from local disk with Viewer("sample.docx") as viewer: html_options = HtmlViewOptions.for_embedded_resources("load_document_from_local_disk/document_from_local_disk_{0}.html") viewer.view(html_options) if __name__ == "__main__": load_document_from_local_disk() ``` {{< /tab >}} {{< tab "sample.docx" >}} {{< tab-text >}} `sample.docx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/developer-guide/loading-documents/load-document-from-local-disk/sample.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "load-document-from-local-disk-outputs.zip" >}} ```text load_document_from_local_disk/document_from_local_disk_1.html (317 KB) load_document_from_local_disk/document_from_local_disk_2.html (149 KB) load_document_from_local_disk/document_from_local_disk_3.html (113 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/developer-guide/loading-documents/load-document-from-local-disk/load_document_from_local_disk/load-document-from-local-disk-outputs.zip) {{< /tab >}} {{< /tabs >}} --- ## Optimize a PDF file for a browser Path: https://docs.groupdocs.com/viewer/python-net/optimization-pdf-for-web/ This optimization allows a browser to display the first pages of a PDF file when you open the document, instead of waiting for the entire file to download. The following code snippet shows how to optimize a PDF file for browser: {{< tabs "Example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions def optimize_pdf_for_web(): # Load document with Viewer("sample.docx") as viewer: viewOptions = PdfViewOptions("optimize_pdf_for_web/optimized_spreadsheet.pdf") viewOptions.pdf_optimization_options = PdfOptimizationOptions() viewOptions.pdf_optimization_options.lineriaze = True viewer.view(viewOptions) if __name__ == "__main__": optimize_pdf_for_web() ``` {{< /tab >}} {{< tab "sample.docx" >}} {{< tab-text >}} `sample.docx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/developer-guide/rendering-documents/rendering-to-pdf/optimization-pdf-options/optimization-pdf-for-web/sample.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "optimized_spreadsheet.pdf" >}} ```text Binary file (PDF, 232 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/developer-guide/rendering-documents/rendering-to-pdf/optimization-pdf-options/optimization-pdf-for-web/optimize_pdf_for_web/optimized_spreadsheet.pdf) {{< /tab >}} {{< /tabs >}} --- ## GroupDocs.Viewer for Python via .NET Overview Path: https://docs.groupdocs.com/viewer/python-net/product-overview/ ## What is GroupDocs.Viewer? GroupDocs.Viewer for Python via .NET is a native Python library that renders **190+ file formats** — DOCX, PDF, XLSX, PPTX, CAD drawings, email messages, compressed archives, eBooks, and raster images — into HTML, PDF, PNG, or JPG output. It runs entirely on-premise, requires no Microsoft Office installation, and ships as a pre-built wheel on Windows, Linux, and macOS. Typical uses include: - **In-app document preview** — embed HTML rendering into desktop or web applications so users can read any document format without leaving the app. - **Server-side rendering pipelines** — convert user uploads to PDF for archival or to per-page PNG for thumbnail generation. - **AI / RAG preprocessing** — render DOCX, XLSX, EML, and scanned PDFs into page-level PNG images or structured HTML that LLMs can consume. See [Agents and LLM Integration]({{< ref "viewer/python-net/agents-and-llm-integration" >}}). - **Redaction and watermarking** — apply text watermarks during rendering, or produce password-protected PDFs from unprotected sources. - **Accessibility and search** — generate semantic HTML from PDFs, DWGs, and legacy office formats for indexing and screen readers. ## Key Capabilities | Capability | Description | |---|---| | **190+ file formats** | DOCX, PDF, XLSX, PPTX, CAD, email, archives, eBooks, HTML, images, and more. See [supported formats]({{< ref "viewer/python-net/getting-started/supported-document-formats.md" >}}). | | **Four output targets** | HTML (embedded or external resources), PDF, PNG, and JPG. Every source format renders to every target. | | **Load options per format** | [Passwords, fonts, encodings, sheet indexes, email fields]({{< ref "viewer/python-net/developer-guide/loading-documents" >}}). | | **View options per target** | DPI, page size, watermarks, rotation, image size limits, PDF permissions — tuned per output format. | | **Page selection** | Render the entire document, a subset of pages, or a single page at a time. | | **Embedded or external HTML resources** | `for_embedded_resources(...)` produces self-contained pages; `for_external_resources(...)` emits separate CSS, font, and image files for indexing systems. | | **Watermarks** | [Add text watermarks]({{< ref "viewer/python-net/developer-guide/rendering-documents/add-text-watermark" >}}) during rendering — color, size, position, opacity. | | **PDF rendering options** | [Protect]({{< ref "viewer/python-net/developer-guide/rendering-documents/rendering-to-pdf/protect-pdf-document" >}}) output PDFs, [reorder pages]({{< ref "viewer/python-net/developer-guide/rendering-documents/rendering-to-pdf/reorder-pages" >}}), adjust image quality, and apply optimization. | | **Attachments** | [Extract attachments]({{< ref "viewer/python-net/developer-guide/processing-attachments/how-to-extract-and-save-attachments" >}}) from emails, archives, and PDFs. | | **Document inspection** | [Read file type, page count, and attachment list]({{< ref "viewer/python-net/developer-guide/get-document-info" >}}) without rendering. | | **Streams** | Load input from file-like objects — handy for cloud blobs and HTTP bodies. | | **Logging and diagnostics** | Wire `ConsoleLogger` through `ViewerSettings` for production traces. | | **On-premise** | No cloud calls, no Microsoft Office install, no network traffic. | ## Quick Example {{< tabs "quick-example">}} {{< tab "quick_example.py" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def quick_example(): """Render a DOCX document to HTML — the hello-world example.""" with Viewer("./sample.docx") as viewer: options = HtmlViewOptions.for_embedded_resources("page_{0}.html") viewer.view(options) if __name__ == "__main__": quick_example() ``` {{< /tab >}} {{< tab "render_with_options.py" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import LoadOptions, PdfViewOptions, Watermark def render_with_options(): """Open a password-protected DOCX, render to PDF with a watermark.""" load_options = LoadOptions() load_options.password = "secret" with Viewer("./protected.docx", load_options) as viewer: options = PdfViewOptions("./protected.pdf") options.watermark = Watermark("CONFIDENTIAL") viewer.view(options) if __name__ == "__main__": render_with_options() ``` {{< /tab >}} {{< tab "quick-outputs.zip" >}} ```text page_1.html (317 KB) page_2.html (149 KB) page_3.html (113 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/product-overview/quick_example/quick-outputs.zip) {{< /tab >}} {{< /tabs >}} ## Where to next 1. **Install the package** — [Installation]({{< ref "viewer/python-net/getting-started/installation" >}}) walks through PyPI and offline wheel installation for Windows, Linux, and macOS. 2. **Run your first rendering** — [Quick Start Guide]({{< ref "viewer/python-net/getting-started/quick-start-guide" >}}) renders a DOCX to HTML, PDF, and PNG in five minutes. 3. **Explore the examples** — [Running Examples]({{< ref "viewer/python-net/getting-started/how-to-run-examples" >}}) clones the runnable repository and runs every documented scenario locally or in Docker. 4. **Use it in depth** — the [Developer Guide]({{< ref "viewer/python-net/developer-guide" >}}) covers loading, rendering, inspecting, page selection, watermarks, and attachments. 5. **Render per format** — the [Rendering Basics]({{< ref "viewer/python-net/rendering-basics" >}}) section has per-format guides for PDF, Word, Excel, presentations, CAD, email, and more. 6. **Plug it into AI pipelines** — [Agents and LLM Integration]({{< ref "viewer/python-net/agents-and-llm-integration" >}}) explains the MCP server, `AGENTS.md`, and how to chain GroupDocs.Viewer with GroupDocs.Conversion for exotic inputs. --- ## Reduce image quality Path: https://docs.groupdocs.com/viewer/python-net/optimization-pdf-reduce-image-quality/ If the output PDF file contains images, you can reduce its size using image compression. To enable image compression, set the [compress_images](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) property to `True`. The GroupDocs.Viewer compresses all images in the file. The [image_quality](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) property determines the compression ratio. It is a quality value in percent. 100% means original quality. The following code snippet shows how to compress images in the file: {{< tabs "Example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions def reduce_image_quality(): # Load document with Viewer("sample.docx") as viewer: viewOptions = PdfViewOptions("reduce_image_quality/reduced_quality.pdf") viewOptions.pdf_optimization_options = PdfOptimizationOptions() viewOptions.pdf_optimization_options.compress_images = True viewOptions.pdf_optimization_options.image_quality = 50 viewer.view(viewOptions) if __name__ == "__main__": reduce_image_quality() ``` {{< /tab >}} {{< tab "sample.docx" >}} {{< tab-text >}} `sample.docx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/developer-guide/rendering-documents/rendering-to-pdf/optimization-pdf-options/optimize-images/optimization-pdf-reduce-image-quality/sample.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "reduced_quality.pdf" >}} ```text Binary file (PDF, 233 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/developer-guide/rendering-documents/rendering-to-pdf/optimization-pdf-options/optimize-images/optimization-pdf-reduce-image-quality/reduce_image_quality/reduced_quality.pdf) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Reduce image quality](https://docs.groupdocs.com/viewer/net/images/developer-guide/pdf-rendering/optimization/optimization-pdf-reduce-image-quality.png) --- ## Remove annotations Path: https://docs.groupdocs.com/viewer/python-net/optimization-pdf-remove-annotations/ If the output PDF file contains annotations, you can remove them to reduce the file size. To remove annotations, set the [remove_annotations](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfoptimizationoptions/#properties) property to `True`. The following code snippet shows how to remove annotations from the file: {{< tabs "Example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions def remove_annotations(): # Load document with Viewer("sample.docx") as viewer: viewOptions = PdfViewOptions("remove_annotations/without_annotations.pdf") viewOptions.pdf_optimization_options = PdfOptimizationOptions() viewOptions.pdf_optimization_options.remove_annotations = True viewer.view(viewOptions) if __name__ == "__main__": remove_annotations() ``` {{< /tab >}} {{< tab "sample.docx" >}} {{< tab-text >}} `sample.docx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/developer-guide/rendering-documents/rendering-to-pdf/optimization-pdf-options/optimize-content/optimization-pdf-remove-annotations/sample.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "without_annotations.pdf" >}} ```text Binary file (PDF, 234 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/developer-guide/rendering-documents/rendering-to-pdf/optimization-pdf-options/optimize-content/optimization-pdf-remove-annotations/remove_annotations/without_annotations.pdf) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Remove annotations](https://docs.groupdocs.com/viewer/net/images/developer-guide/pdf-rendering/optimization/optimization-pdf-remove-annotations.png) --- ## Render CAD drawings and models as HTML, PDF, and image files Path: https://docs.groupdocs.com/viewer/python-net/render-cad-drawings-and-models/ [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) --- ## Render Excel and Apple Numbers spreadsheets as HTML, PDF, and image files Path: https://docs.groupdocs.com/viewer/python-net/render-excel-and-apple-numbers-spreadsheets/ [GroupDocs.Viewer for Python](https://products.groupdocs.com/viewer/python-net) allows you to render your spreadsheet files in HTML, PDF, PNG, and JPEG formats. You do not need to use Microsoft Excel or other spreadsheet programs to load and view Excel documents within your Python application (web or desktop). To start with the GroupDocs.Viewer API, create a [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) class instance. Pass a spreadsheet file you want to view to the class constructor. You can load the document 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 document to HTML, PDF, or image format. These methods allow you to render the entire document or specific pages. {{< button style="primary" link="https://products.groupdocs.app/viewer/excel" >}} {{< icon "gdoc_person" >}} View Excel 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 spreadsheet file formats GroupDocs.Viewer supports the following spreadsheet file formats: * [Microsoft Excel Workbook](https://docs.fileformat.com/spreadsheet/xlsx) (.XLSX) * [Microsoft Excel 97-2003 Workbook](https://docs.fileformat.com/spreadsheet/xls) (.XLS) * [Microsoft Excel Binary Workbook](https://docs.fileformat.com/spreadsheet/xlsb) (.XLSB) * [Microsoft Excel Macro-Enabled Workbook](https://docs.fileformat.com/spreadsheet/xlsm) (.XLSM) * [Microsoft Excel Template](https://docs.fileformat.com/spreadsheet/xltx) (.XLTX) * [Microsoft Excel 97-2003 Template](https://docs.fileformat.com/spreadsheet/xlt) (.XLT) * [Microsoft Excel Macro-Enabled Template](https://docs.fileformat.com/spreadsheet/xltm) (.XLTM) * [Microsoft Excel Add-In](https://docs.fileformat.com/spreadsheet/xlam/) (.XLAM) * [XML Spreadsheet 2003](https://en.wikipedia.org/wiki/SpreadsheetML) (.XML) * [OpenDocument Spreadsheet](https://docs.fileformat.com/spreadsheet/ods) (.ODS) * [OpenDocument Spreadsheet Template](https://docs.fileformat.com/spreadsheet/ots/) (.OTS) * [OpenDocument Flat XML Spreadsheet](https://docs.fileformat.com/spreadsheet/fods/) (.FODS) * [Comma Separated Values File](https://docs.fileformat.com/spreadsheet/csv) (.CSV) * [Tab Separated Values File](https://docs.fileformat.com/spreadsheet/tsv) (.TSV) * [StarOffice Calc Spreadsheet](https://docs.fileformat.com/spreadsheet/sxc/) (.SXC) * [Apple Numbers Spreadsheet](https://docs.fileformat.com/spreadsheet/numbers) (.NUMBERS) ## Render spreadsheets 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 spreadsheet file to HTML. 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. #### Convert an Excel workbook to HTML {{< tabs "example1">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_excel_to_html(): # Load Excel spreadsheet with Viewer("invoice.xlsx") as viewer: # Convert the spreadsheet to HTML. # {0} is replaced with the current page number in the file names. viewOptions = HtmlViewOptions.for_embedded_resources("render_excel_to_html/pdf_page_{0}.html") viewer.view(viewOptions) if __name__ == "__main__": render_excel_to_html() ``` {{< /tab >}} {{< tab "invoice.xlsx" >}} {{< tab-text >}} `invoice.xlsx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/invoice.xlsx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-excel-to-html-outputs.zip" >}} ```text render_excel_to_html/pdf_page_1.html (51 KB) render_excel_to_html/pdf_page_10.html (49 KB) render_excel_to_html/pdf_page_11.html (48 KB) render_excel_to_html/pdf_page_12.html (46 KB) render_excel_to_html/pdf_page_13.html (50 KB) render_excel_to_html/pdf_page_14.html (33 KB) render_excel_to_html/pdf_page_15.html (51 KB) render_excel_to_html/pdf_page_16.html (49 KB) render_excel_to_html/pdf_page_17.html (48 KB) render_excel_to_html/pdf_page_18.html (47 KB) [TRUNCATED] (42 files total) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/render_excel_to_html/render-excel-to-html-outputs.zip) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Render an Excel file to HTML](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-spreadsheets/convert-excel-to-html.png) #### Convert an Apple Numbers spreadsheet to HTML {{< tabs "example2">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_numbers_to_html(): # Load Apple Numbers spreadsheet with Viewer("sample.numbers") as viewer: # Convert the spreadsheet to HTML. # {0} is replaced with the current page number in the file names. viewOptions = HtmlViewOptions.for_embedded_resources("render_numbers_to_html/pdf_page_{0}.html") viewer.view(viewOptions) if __name__ == "__main__": render_numbers_to_html() ``` {{< /tab >}} {{< tab "sample.numbers" >}} {{< tab-text >}} `sample.numbers` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/sample.numbers) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-numbers-to-html-outputs.zip" >}} ```text render_numbers_to_html/pdf_page_1.html (41 KB) render_numbers_to_html/pdf_page_2.html (34 KB) render_numbers_to_html/pdf_page_3.html (25 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/render_numbers_to_html/render-numbers-to-html-outputs.zip) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Render an Apple Numbers spreadsheet to HTML](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-spreadsheets/render-apple-numbers-to-html.png) ### Create an HTML file with external resources If you want to store an HTML file and additional resource files (such as fonts, images, and stylesheets) separately, call the [HtmlViewOptions.for_external_resources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) method and pass the following parameters: * The output file path format * The path format for the folder with external resources * The resource URL format #### Convert an Excel workbook to HTML {{< tabs "example3">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_excel_to_html_external(): # Load Excel spreadsheet with Viewer("invoice.xlsx") as viewer: # Convert the spreadsheet to HTML. # Specify the HTML file names and location of external resources. # {0} and {1} are replaced with the current page number and resource name, respectively. viewOptions = HtmlViewOptions.for_external_resources("render_excel_to_html_external/pdf_page_{0}.html", "render_excel_to_html_external/pdf_page_{0}/resource_{0}_{1}", "render_excel_to_html_external/pdf_page_{0}/resource_{0}_{1}") viewer.view(viewOptions) if __name__ == "__main__": render_excel_to_html_external() ``` {{< /tab >}} {{< tab "invoice.xlsx" >}} {{< tab-text >}} `invoice.xlsx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/invoice.xlsx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-excel-to-html-external-outputs.zip" >}} ```text render_excel_to_html_external/pdf_page_1.html (17 KB) render_excel_to_html_external/pdf_page_10.html (25 KB) render_excel_to_html_external/pdf_page_10/resource_10_s.css (3 KB) render_excel_to_html_external/pdf_page_11.html (25 KB) render_excel_to_html_external/pdf_page_11/resource_11_s.css (3 KB) render_excel_to_html_external/pdf_page_12.html (25 KB) render_excel_to_html_external/pdf_page_12/resource_12_s.css (3 KB) render_excel_to_html_external/pdf_page_13.html (25 KB) render_excel_to_html_external/pdf_page_13/resource_13_s.css (3 KB) render_excel_to_html_external/pdf_page_14.html (11 KB) [TRUNCATED] (84 files total) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/render_excel_to_html_external/render-excel-to-html-external-outputs.zip) {{< /tab >}} {{< /tabs >}} #### Convert an Apple Numbers spreadsheet to HTML {{< tabs "example4">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_numbers_to_html_external(): # Load Apple Numbers spreadsheet with Viewer("sample.numbers") as viewer: # Convert the spreadsheet to HTML. # Specify the HTML file names and location of external resources. # {0} and {1} are replaced with the current page number and resource name, respectively. viewOptions = HtmlViewOptions.for_external_resources("render_numbers_to_html_external/pdf_page_{0}.html", "render_numbers_to_html_external/pdf_page_{0}/resource_{0}_{1}", "render_numbers_to_html_external/pdf_page_{0}/resource_{0}_{1}") viewer.view(viewOptions) if __name__ == "__main__": render_numbers_to_html_external() ``` {{< /tab >}} {{< tab "sample.numbers" >}} {{< tab-text >}} `sample.numbers` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/sample.numbers) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-numbers-to-html-external-outputs.zip" >}} ```text render_numbers_to_html_external/pdf_page_1.html (15 KB) render_numbers_to_html_external/pdf_page_1/resource_1_s.css (2 KB) render_numbers_to_html_external/pdf_page_2.html (15 KB) render_numbers_to_html_external/pdf_page_2/resource_2_s.css (2 KB) render_numbers_to_html_external/pdf_page_3.html (6 KB) render_numbers_to_html_external/pdf_page_3/resource_3_s.css (2 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/render_numbers_to_html_external/render-numbers-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/python-net/images/rendering-basics/render-spreadsheets/render-excel-to-html-external-resources.png) ### Convert all Excel worksheets to one HTML file To convert all worksheets to one HTML file, use the [HtmlViewOptions.render_to_single_page](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) method. This feature is supported in both cases - when converting to HTML with embedded and external resources. {{< tabs "example5">}} {{< tab "Python" >}} ```python from groupdocs.viewer import Viewer from groupdocs.viewer.options import HtmlViewOptions def render_excel_to_single_html(): # Load Excel spreadsheet with Viewer("invoice.xlsx") as viewer: # Convert all Excel worksheets to one HTML file. viewOptions = HtmlViewOptions.for_embedded_resources("render_excel_to_single_html/page.html") # Enable converting all worksheets to one file. viewOptions.render_to_single_page = True viewer.view(viewOptions) if __name__ == "__main__": render_excel_to_single_html() ``` {{< /tab >}} {{< tab "invoice.xlsx" >}} {{< tab-text >}} `invoice.xlsx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-spreadsheets/render-excel-and-apple-numbers-spreadsheets/invoice.xlsx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "page.html" >}} ```text 
London is the capital city of England and the United Kingdom, and the most popul
[TRUNCATED]
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-text-files/render_text_to_html/pdf_page_1.html)
{{< /tab >}}
{{< /tabs >}}

The following image demonstrates the result:

![Render a text file to HTML](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-text-files/render-to-html-embedded-resources.png)

### Create HTML files with external resources

If you want to store output HTML files and additional resource files (such as fonts, images, and style sheets) separately, call the [HtmlViewOptions.for_external_resources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) method and pass the following parameters:

  * The output file path format
  * The path format for the folder with external resources
  * The resource URL format

{{< tabs "example4">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_text_to_html_external():
    # Load text file
    with Viewer("terms_of_service.txt") as viewer:
        # Create an HTML file for each page.
        # Specify the HTML file names and location of external resources.
        # {0} and {1} are replaced with the current page number and resource name, respectively.
        viewOptions = HtmlViewOptions.for_external_resources("render_text_to_html_external/pdf_page_{0}.html", "render_text_to_html_external/pdf_page_{0}/resource_{0}_{1}", "render_text_to_html_external/pdf_page_{0}/resource_{0}_{1}")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_text_to_html_external()
```
{{< /tab >}}
{{< tab "terms_of_service.txt" >}}
{{< tab-text >}}
`terms_of_service.txt` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-text-files/terms_of_service.txt) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "render-text-to-html-external-outputs.zip" >}}  
```text
render_text_to_html_external/pdf_page_1.html (3 KB)
render_text_to_html_external/pdf_page_1/resource_1_s.css (109 bytes)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-text-files/render_text_to_html_external/render-text-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/python-net/images/rendering-basics/render-text-files/render-to-html-external-resources.png)

### Create a single HTML page

If you need to display the entire document content on a single HTML page, use the [HtmlViewOptions.setRenderToSinglePage](#) method, as shown below:

{{< tabs "example5">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_text_to_single_html():
    # Load text file
    with Viewer("terms_of_service.txt") as viewer:
        # Create an HTML file.
        viewOptions = HtmlViewOptions.for_embedded_resources("render_text_to_single_html/text_to_single_html.html")
        # Render the file to a single page. 
        viewOptions.render_to_single_page = True
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_text_to_single_html()
```
{{< /tab >}}
{{< tab "terms_of_service.txt" >}}
{{< tab-text >}}
`terms_of_service.txt` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-text-files/terms_of_service.txt) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "text_to_single_html.html" >}}  
```text
terms_of_service.txt 
London is the capital city of England and the United Kingdom, and the most popul
[TRUNCATED]
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-text-files/render_text_to_single_html/text_to_single_html.html)
{{< /tab >}}
{{< /tabs >}}

## Render text files 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 text 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 "example6">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions

def render_text_to_pdf():
    # Load text file
    with Viewer("terms_of_service.txt") as viewer:
        # Convert the text file to PDF.
        viewOptions = PdfViewOptions("render_text_to_pdf/text_document.pdf")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_text_to_pdf()
```
{{< /tab >}}
{{< tab "terms_of_service.txt" >}}
{{< tab-text >}}
`terms_of_service.txt` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-text-files/terms_of_service.txt) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "text_document.pdf" >}}  
```text
Binary file (PDF, 30 KB)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-text-files/render_text_to_pdf/text_document.pdf)
{{< /tab >}}
{{< /tabs >}}

The following image demonstrates the result:

![Render a text file to PDF](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-text-files/render-to-pdf.png)

## Render text files 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 text 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) methods to specify the output image size in pixels.

{{< tabs "example7">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions

def render_text_to_png():
    # Load text file
    with Viewer("terms_of_service.txt") as viewer:
        # Convert the text file to PNG.
        # {0} is replaced with the current page number in the output image names.
        viewOptions = PngViewOptions("render_text_to_png/text_page_0_{0}.png")
        # Set width and height.
        viewOptions.width = 950
        viewOptions.height = 550
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_text_to_png()
```
{{< /tab >}}
{{< tab "terms_of_service.txt" >}}
{{< tab-text >}}
`terms_of_service.txt` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-text-files/terms_of_service.txt) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "text_page_0_1.png" >}}  
```text
Binary file (PNG, 126 KB)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-text-files/render_text_to_png/text_page_0_1.png)
{{< /tab >}}
{{< /tabs >}}

The following image demonstrates the result:

![Render a text file to PNG](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-text-files/render-to-png-image.png)

## Render text files 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 text 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) methods to specify the output image size in pixels.

{{< tabs "example8">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import JpgViewOptions

def render_text_to_jpg():
    # Load text file
    with Viewer("terms_of_service.txt") as viewer:
        # Convert the text file to JPEG.
        # {0} is replaced with the current page number in the output image names.
        viewOptions = JpgViewOptions("render_text_to_jpg/text_to_jpg_{0}.jpg")
        # Set width and height.
        viewOptions.width = 950
        viewOptions.height = 550
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_text_to_jpg()
```
{{< /tab >}}
{{< tab "terms_of_service.txt" >}}
{{< tab-text >}}
`terms_of_service.txt` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-text-files/terms_of_service.txt) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "text_to_jpg_1.jpg" >}}  
```text
Binary file (JPG, 110 KB)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-text-files/render_text_to_jpg/text_to_jpg_1.jpg)
{{< /tab >}}
{{< /tabs >}}
---

## Render XML documents as HTML, PDF, PNG, and JPEG files

Path: https://docs.groupdocs.com/viewer/python-net/render-xml-documents/

[GroupDocs.Viewer for Python via .NET](https://products.groupdocs.com/viewer/python-net) started to support XML format a long time ago, but XML documents were treated as plain text, and thus it was not as useful as it might be. Starting from [version 24.9](https://releases.groupdocs.com/viewer/python-net/release-notes/2024/groupdocs-viewer-for-python-via-net-24-9-release-notes/#new-xml-converter), the completely new XML processing module was implemented, and now XML documents are processed differently, not as plain text documents. This article explains this new XML processing module.

## Opening the XML document

First of all need to emphasize that the new XML processing module had not touched the public API at all — no new options, classes, properties or methods were added or modified. In order to process input XML document properly using the new XML processing module, need to either specify the [`LoadOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/loadoptions/) class instance with [`FileType.XML`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/filetype/) in its [constructor](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/loadoptions/#constructors) or just pass the XML document as filename with `*.xml` extension. Code example below shows all possible ways:

{{< tabs "Loading example">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer, FileType
from groupdocs.viewer.options import LoadOptions

def load_xml_document():
    # Method 1: Load XML document by specifying filename with .xml extension
    # GroupDocs.Viewer automatically detects XML format from file extension
    with Viewer("sample.xml") as viewer:
        # Render document
        pass

    # Method 2: Load XML document by explicitly specifying file type in LoadOptions
    # Create load options and set file type to XML
    load_options = LoadOptions()
    load_options.file_type = FileType.XML

    # Load XML document with explicit load options
    with Viewer("sample.xml", load_options) as viewer:
        # Render document
        pass

if __name__ == "__main__":
    load_xml_document()
```
{{< /tab >}}
{{< tab "sample.xml" >}}
{{< tab-text >}}
`sample.xml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-xml-documents/sample.xml) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< /tabs >}}


If the instance of the [`Viewer`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) class is initialized using one of the ways described above, the new XML processing module will be used.

By default all XML documents must have an [XML declaration](https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction#xml_declaration), which is located in the very beginning of the XML document and which stores the encoding of the consecutive content, for example: 

``

By default GroupDocs.Viewer uses it. But there is a possibility to override this character encoding, if needed. In order to do this the [`LoadOptions.encoding`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/loadoptions/#properties) property should be set while initializing the [`Viewer`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) class, as it is shown below:

{{< tabs "Custom encoding example">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer, FileType
from groupdocs.viewer.options import LoadOptions

def load_xml_with_encoding():
    # Create load options for XML file type
    load_options = LoadOptions(FileType.XML)
    # Override the encoding specified in XML declaration
    # This allows you to use a different encoding than what's declared in the XML file
    load_options.encoding = "ASCII"

    # Load XML document with custom encoding
    with Viewer("sample.xml", load_options) as viewer:
        # Render document
        pass

if __name__ == "__main__":
    load_xml_with_encoding()
```
{{< /tab >}}
{{< tab "sample.xml" >}}
{{< tab-text >}}
`sample.xml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-xml-documents/sample.xml) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< /tabs >}}


The rest of this article explains features of this new XML processing module.

## Representation

The main task of the new XML processing module is to represent the XML markup, obtained from the user, in a structured, formatted, hierarchical view, with highlighting of every distinct entity of this XML structure. For the GroupDocs.Viewer there is no matter how human-friendly is represented the XML markup in original document: it may be divided by line breaks onto separate lines per every element, or the whole document may be stored in a single line of text; it may have indents or not, — all of this does not matter. The GroupDocs.Viewer parses the input XML document and creates a hierarchical Document Object Model (DOM), and then serializes it to the HTML, PDF, PNG or JPEG depending on user options.

In particular, when serializing, GroupDocs.Viewer puts every XML element (node) on a new line, and with left indent, which indicates nesting of a certain element. Every entity of the XML document, — XML element, attribute, its value, text node, XML comment, CDATA section, — has its own highlighting: font style, type, color, size and so on. All quotes, used for enquoting the attribute values, are unified.

The screenshot below shows such scenario. On the left side there is a [sample XML document](https://docs.groupdocs.com/viewer/net/sample-files/render-xml-documents/books-single-line.xml), where all content is stored within a single line, with no indents, line breaks, horizontal tabs, or even extra whitespaces. On the right side the resultant HTML file, generated by the GroupDocs.Viewer, is shown. There can be seen structured view with corrent line breaks and indents, valid highlighting of every XML entity, and recognition of the URIs and email addresses.

![Generate HTML view for input XML](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-xml-documents/XML-to-HTML.png)

## Fix incorrect XML structure

The World Wide Web Consortium has clearly defined what is a valid XML document, and what is not. The term “[well-formed document](https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction#correct_xml_valid_and_well-formed)” defines a those XML document, which "adheres to the syntax rules specified by the XML 1.0 specification in that it must satisfy both physical and logical structures"([ref](http://www.csdservices.com/articles/csdservices)). In particular, a valid XML document must contain only valid characters, its start tags and end tags must be matched, correctly opened and closed, elements must be properly nested, and so on. Unfortunately, not all existing XML documents are well-formed and sometimes there is a necessity to view them. Different XML markup viewers often are unable to properly show invalid XML documents.

GroupDocs.Viewer with its new XML processing module is able to correctly parse, process, format, highlight and view even the heavily distorted XML documents. There is partial list of different damages in XML structure, which GroupDocs.Viewer can fix and process:

- Invalid and illegal characters, including `<` and `&` characters in wrong places.
- Start tags, which are not closed.
- End tags, which are not opened.
- Interleaved (overlapped) tags.
- Start and end tags with unmatched letter cases.
- Truncated (cutted from end) markup.
- Attribute names without values.
- Un-enquoted attribute values (without enclosing quotes).
- Attribute values, which are enquoted partially, with only opening or only closing quote.
- Attribute values, which have redundant quote inside.

GroupDocs.Viewer detects and fixes all these and even more issues in XML markup and also writes them to the log.

Screenshot below demonstrates this in action. [Sample XML file "InvalidXml.xml"](https://docs.groupdocs.com/viewer/net/sample-files/render-xml-documents/InvalidXml.xml) contains all possible damages, described above. In cannot be correctly formatted and highlighted by most popular XML viewing and editing applications. But with the new XML processing module the GroupDocs.Viewer fixes its structure and displays it absolutely correct.

![Generate HTML view for input XML](https://docs.groupdocs.com/viewer/net/images/rendering-basics/render-xml-documents/XML-fixed.png)

## Recognition of URIs and email addresses

While processing the XML markup, the GroupDocs.Viewer scans the XML content for any valid URI, if found, represents them as external links in the resultant HTML format: by using the [A element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a). GroupDocs.Viewer is searching for URIs in: text nodes, CDATA sections, XML comments, attribute values, DocType definitions.

Regarding the email addresses, the GroupDocs.Viewer searches them only in attribute values, and if found, represents them with [mailto](https://en.wikipedia.org/wiki/Mailto) scheme and [A element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a).

If the XML document is saved not to the HTML format, but to the PDF, the URIs and email addresses will be interactive too. But if the output format is PNG or JPEG, the output will be a raster image without any interactive links, of course.

## Saving to HTML format

For saving the documents to the HTML format the GroupDocs.Viewer provides a [`HtmlViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) class. There are two ways of creating an instance of this class: using either [`for_external_resources`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) or [`for_embedded_resources`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#methods) static methods. First method is designed for saving HTML document in a such way, that all its resources (stylesheets, images, fonts etc) are stored separately, while second method stores all resources of the HTML document inside its content: stylesheets are saved inside the STYLE elements, SVG graphics is inlined inside HTML markup, while all other resources (mostly raster images and fonts) are stored according to the [data URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme) and converted to the [base64](https://en.wikipedia.org/wiki/Base64) format.

But in the context of the XML documents the way of creating the [`HtmlViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) instance is not important, because the XML documents cannot have resources, which may be stored externally or embedded. So, when saving XML documents to the HTML, you can create the [`HtmlViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) instance in both ways — the result will be the same, no external resources will be produced.

Another important thing is that the XML format by its nature has no pages — it is a hierarchical structure, where some elements are nested inside another, and there is no even similar to pages here. So the best way to represent them in HTML format is to generate a single-page HTML document, so all XML content will be represented in a single HTML document. In order to do this the option [`HtmlViewOptions.render_to_single_page`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#properties) needs to be set up to the true value. By default this option has a false value, so the output HTML document will be paginated — splitted into multiple chunks.

Code example below shows rendering of input XML file to the HTML in both ways:

{{< tabs "Saving to HTML example">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions

def render_xml_to_html():
    # Create HTML view options for paginated output
    # {0} will be replaced with page number
    paginated_html_options = HtmlViewOptions.for_embedded_resources("render_xml_to_html/page-{0}.html")
    
    # Create HTML view options for single-page output
    single_html_options = HtmlViewOptions.for_embedded_resources("render_xml_to_html/single-page.html")
    # Enable single-page rendering - all XML content in one HTML file
    single_html_options.render_to_single_page = True

    # Load XML document
    with Viewer("sample.xml") as viewer:
        # Render to paginated HTML (multiple HTML files)
        viewer.view(paginated_html_options)
        # Render to single-page HTML (one HTML file)
        viewer.view(single_html_options)

if __name__ == "__main__":
    render_xml_to_html()
```
{{< /tab >}}
{{< tab "sample.xml" >}}
{{< tab-text >}}
`sample.xml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-xml-documents/sample.xml) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "render-xml-to-html-outputs.zip" >}}  
```text
render_xml_to_html/page-1.html (36 KB)
render_xml_to_html/single-page.html (9 KB)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-xml-documents/render_xml_to_html/render-xml-to-html-outputs.zip)
{{< /tab >}}
{{< /tabs >}}

All other options, which are present in the [`HtmlViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/) class, have no effect when saving XML to HTML, except the [`render_to_single_page`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions/#properties) flag.

## Saving to PDF format

PDF format by its nature has pages, so if the XML content because of its big size cannot fit in the single PDF page, then it will be paginated. Unlike the HTML, PNG, or JPEG, the GroupDocs.Viewer generates only a single PDF file for a single input XML document, with one or more pages. [`PdfViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/) class is responsible for saving XML to the PDF, and example below shows this:

{{< tabs "Saving to PDF example">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions

def render_xml_to_pdf():
    # Create PDF view options and specify output file path
    pdf_options = PdfViewOptions("render_xml_to_pdf/xml_document.pdf")
    
    # Load XML document
    with Viewer("sample.xml") as viewer:
        # Render XML document to PDF format
        # If content is large, it will be automatically paginated
        viewer.view(pdf_options)

if __name__ == "__main__":
    render_xml_to_pdf()
```
{{< /tab >}}
{{< tab "sample.xml" >}}
{{< tab-text >}}
`sample.xml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-xml-documents/sample.xml) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "xml_document.pdf" >}}  
```text
Binary file (PDF, 22 KB)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-xml-documents/render_xml_to_pdf/xml_document.pdf)
{{< /tab >}}
{{< /tabs >}}

As for the version 24.8 all options, which are present in the [`PdfViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pdfviewoptions/) class, have no effect when saving XML to PDF.

## Saving to raster PNG and JPEG formats

[`PngViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/) and [`JpgViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/) are responsible for saving XML to the PNG and JPEG raster image formats. Like for the PDF, if XML content cannot fit into the area of one image, it will be paginated and spread across multiple images.

Size of the output images will be calculated automatically based on the XML content, as for the version 24.8 there is no possibility to set the size forcibly, and `width`, `height`, `max_width`, and `max_height` properties of the [`PngViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/) and [`JpgViewOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/) classes have no effect when saving XML to PNG or JPEG.

There is a possibility to set a quality of output JPEG image by setting a [`JpgViewOptions.quality`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/jpgviewoptions/#properties) instance property, which has a default value `90`.

Example below shows saving input XML to the output PNG and JPEG:

{{< tabs "Saving to PNG and JPEG example">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PngViewOptions, JpgViewOptions

def render_xml_to_images():
    # Create PNG view options
    # {0} will be replaced with page number if content spans multiple images
    pngOptions = PngViewOptions("render_xml_to_images/page-{0}.png")
    
    # Create JPEG view options
    jpegOptions = JpgViewOptions("render_xml_to_images/page-{0}.jpeg")
    # Set JPEG image quality (1-100, default is 90)
    jpegOptions.quality = 80

    # Load XML document
    with Viewer("sample.xml") as viewer:
        # Render XML document to PNG format
        viewer.view(pngOptions)
        # Render XML document to JPEG format
        viewer.view(jpegOptions)

if __name__ == "__main__":
    render_xml_to_images()
```
{{< /tab >}}
{{< tab "sample.xml" >}}
{{< tab-text >}}
`sample.xml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-xml-documents/sample.xml) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< tab "render-xml-to-images-outputs.zip" >}}  
```text
render_xml_to_images/page-1.jpeg (36 KB)
render_xml_to_images/page-1.png (27 KB)
```
[Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-xml-documents/render_xml_to_images/render-xml-to-images-outputs.zip)
{{< /tab >}}
{{< /tabs >}}

## Retrieving information about XML view

Like for all other supported formats, GroupDocs.Viewer supports returning information about specific XML documents. Like for all other formats, for doing this you need to call the [`get_view_info`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) instance method of the [`Viewer`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/) class, which returns an instance of [`ViewInfo`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.results/viewinfo/) class. This [`ViewInfo`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.results/viewinfo/) instance contains all information about the view depending on [`ViewInfoOptions`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/viewinfooptions/), passed to the [`get_view_info`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer/#methods) method.

Example below shows obtaining [`ViewInfo`](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.results/viewinfo/) for a single XML document for HTML, PDF, and PNG formats.

{{< tabs "Retrieving information about XML view example">}}
{{< tab "Python" >}}
```python
from groupdocs.viewer import Viewer
from groupdocs.viewer.options import ViewInfoOptions

def get_xml_view_info():
    # Create view info options for HTML format (single page)
    view_info_options_html_single = ViewInfoOptions.for_html_view(True)
    # Create view info options for PDF format
    view_info_options_pdf = ViewInfoOptions.for_pdf_view()
    # Create view info options for PNG format
    view_info_options_png = ViewInfoOptions.for_png_view()

    # Load XML document
    with Viewer("sample.xml") as viewer:
        # Get view information for HTML format (single page)
        result_html_single = viewer.get_view_info(view_info_options_html_single)  
        # Get view information for PDF format
        result_pdf = viewer.get_view_info(view_info_options_pdf) 
        # Get view information for PNG format
        result_png = viewer.get_view_info(view_info_options_png)

if __name__ == "__main__":
    get_xml_view_info()
```
{{< /tab >}}
{{< tab "sample.xml" >}}
{{< tab-text >}}
`sample.xml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-xml-documents/sample.xml) to download it.
{{< /tab-text >}}
{{< /tab >}}
{{< /tabs >}}
---

## Technical Support

Path: https://docs.groupdocs.com/viewer/python-net/technical-support/


GroupDocs provides unlimited free technical support for all of its products. Support is available to all users, including those evaluating the product. You can access support at the [Free Support Forum](https://forum.groupdocs.com/) and the [Paid Support Helpdesk](https://helpdesk.groupdocs.com/).

{{< alert style="info" >}}
Please note that GroupDocs does not offer technical support by phone. Phone support is available only for sales and purchase inquiries.
{{< /alert >}}

## GroupDocs Free Support Forum

If you need assistance with GroupDocs.Viewer, please consider the following:

1. Ensure you are using the latest version of GroupDocs.Viewer before reporting an issue. Check the [releases page](https://releases.groupdocs.com/viewer/python-net/) for the latest version.
2. Review the forums and this documentation to see if your question has already been answered.
3. Post your question in the [GroupDocs.Viewer Free Support Forum](https://forum.groupdocs.com/c/viewer). Our development team will assist you directly.
4. Please allow for time zone differences when waiting for a reply on the forums.

## Paid Support Helpdesk

Paid support requests are given higher priority than free support requests.

1. Post your question at the [Paid Support Helpdesk](https://helpdesk.groupdocs.com/) to receive higher priority assistance.

## Report an Issue or Feature Request

To ensure your issue, question, or feature request is resolved efficiently, please follow these steps:

1. Attach the original document and any relevant code snippet that reproduces the issue. If you need to attach multiple files, compress them into a single archive. It’s safe to attach documents on the GroupDocs Forum, as only you and GroupDocs developers will have access.
2. Include details about the environment where the issue occurs.
3. Report one issue per thread. If you have additional questions, issues, or feature requests, please create separate threads for each.

---

## Render images as HTML, PDF, PNG, and JPEG files

Path: https://docs.groupdocs.com/viewer/python-net/render-images/

[GroupDocs.Viewer for Python via .NET](https://products.groupdocs.com/viewer/python-net) allows you to load images in various formats and convert them to HTML, PDF, PNG, and JPEG. Incorporate this library into your Python application (web or desktop) to build your own image viewer.

To start with the GroupDocs.Viewer API, create a [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) class instance. Pass an image you want to view to the class constructor. You can load the image 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 image to HTML, PDF, PNG, or JPEG format. For multipage images (such as TIFF, CDR, DICOM, WebP, and so on), you can specify the pages to render.

{{< button style="primary" link="https://products.groupdocs.app/viewer/image" >}} {{< icon "gdoc_person" >}} View image files online {{< /button >}} {{< button style="primary" link="https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-Python-via-Python" >}} {{< icon "gdoc_github" >}} View demos and examples on GitHub {{< /button >}}

## Supported image file formats

GroupDocs.Viewer supports the following image file formats:

* [.AI (Adobe Illustrator Artwork)](https://docs.fileformat.com/image/ai/)
* [.APNG (Animated Portable Network Graphic)](https://docs.fileformat.com/image/apng/)
* [.BMP (Bitmap Image)](https://docs.fileformat.com/image/bmp)
* [.CDR (CorelDRAW Image File)](https://docs.fileformat.com/image/cdr)
* [.CGM (Computer Graphics Metafile)](https://docs.fileformat.com/page-description-language/cgm)
* [.CMX (Corel Presentation Exchange Image)](https://docs.fileformat.com/image/cmx)
* [.DCM (DICOM Image)](https://docs.fileformat.com/image/dicom)
* [.DIB (Device Independent Bitmap File)](https://docs.fileformat.com/image/dib)
* [.DJVU (DjVu Image)](https://docs.fileformat.com/image/djvu)
* [.DNG (Digital Negative Image)](https://docs.fileformat.com/image/dng)
* [.EMF (Enhanced Windows Metafile)](https://docs.fileformat.com/image/emf)
* [.EMZ (Windows Compressed Enhanced Metafile)](https://docs.fileformat.com/image/emz/)
* [.EPS (Encapsulated PostScript File)](https://docs.fileformat.com/page-description-language/eps)
* [.FODG (OpenDocument Flat XML Graphics)](https://docs.fileformat.com/image/fodg/)
* [.GIF (Graphical Interchange Format)](https://docs.fileformat.com/image/gif)
* [.ICO (Icon File)](https://docs.fileformat.com/image/ico)
* [.J2C (JPEG 2000 Code Stream)](https://docs.fileformat.com/image/j2c/)
* [.J2K (JPEG 2000 Image)](https://docs.fileformat.com/image/j2k/)
* [.JP2 (JPEG 2000 Core Image File)](https://docs.fileformat.com/image/jp2/)
* [.JPC (JPEG 2000 Code Stream File)](https://docs.fileformat.com/image/jpc/)
* [.JPEG / .JPG (JPEG Image)](https://docs.fileformat.com/image/jpeg)
* [.JPF (JPEG 2000 Image)](https://docs.fileformat.com/image/jpf/)
* [.JPM (JPEG 2000 Multi-layer Image Format)](https://docs.fileformat.com/image/jpm/)
* [.JPX (JPEG 2000 Image File)](https://docs.fileformat.com/image/jpx/)
* [.JLS (JPEG-LS Image)](https://docs.fileformat.com/)
* [.ODG (OpenDocument Graphics File)](https://docs.fileformat.com/image/odg)
* [.OTG (OpenDocument Graphic Template)](https://docs.fileformat.com/image/otg/)
* [.PCL (Printer Command Language Document)](https://docs.fileformat.com/page-description-language/pcl)
* [.PNG (Portable Network Graphics)](https://docs.fileformat.com/image/png)
* [.PS (PostScript File)](https://docs.fileformat.com/page-description-language/ps)
* [.PSB (Photoshop Large Document Format)](https://docs.fileformat.com/image/psb)
* [.PSD (Adobe Photoshop Document)](https://docs.fileformat.com/image/psd)
* [.SVG (Scalable Vector Graphics File)](https://docs.fileformat.com/page-description-language/svg)
* [.SVGZ (Compressed SVG File)](https://docs.fileformat.com/image/svgz/)
* [.TGA (TARGA Graphics)](https://docs.fileformat.com/image/tga/) 
* [.TIF / .TIFF (Tagged Image File Format)](https://docs.fileformat.com/image/tiff)
* [.WEBP (WebP Image)](https://docs.fileformat.com/image/webp)
* [.WMF (Windows Metafile)](https://docs.fileformat.com/image/wmf)
* [.WMZ (Compressed Windows Metafile)](https://docs.fileformat.com/image/wmz/)

## Render images 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 an image to HTML. 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 embed an image in an HTML page, call the [HtmlViewOptions.for_embedded_resources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/htmlviewoptions) 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_image_to_html():
    # Load image
    with Viewer("vector-image.svg") as viewer:
        # Specify the HTML file name.
        viewOptions = HtmlViewOptions.for_embedded_resources("render_image_to_html/pdf_page_{0}.html")
        viewer.view(viewOptions)

if __name__ == "__main__":
    render_image_to_html()
```
{{< /tab >}}
{{< tab "vector-image.svg" >}}
{{< tab-text >}}
`vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-images/vector-image.svg) 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_image_to_html_external(): # Load image with Viewer("vector-image.svg") as viewer: # Specify the HTML file name and location of external resources. # {0} is replaced with the resource name in the output file name. viewOptions = HtmlViewOptions.for_external_resources("render_image_to_html_external/pdf_page_{0}.html", "render_image_to_html_external/pdf_page_{0}/resource_{0}_{1}", "render_image_to_html_external/pdf_page_{0}/resource_{0}_{1}") viewer.view(viewOptions) if __name__ == "__main__": render_image_to_html_external() ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "render-image-to-html-external-outputs.zip" >}} ```text render_image_to_html_external/pdf_page_1.html (309 bytes) render_image_to_html_external/pdf_page_1/resource_1_g.svg (129 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-images/render_image_to_html_external/render-image-to-html-external-outputs.zip) {{< /tab >}} {{< /tabs >}} The result is shown below. The image is placed in a separate folder. ![Place HTML resources in a separate folder](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-images/render-image-to-html-external-resources.png) ## Render images 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 an image 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_image_to_pdf(): # Load image with Viewer("vector-image.svg") as viewer: # Create a PDF file. viewOptions = PdfViewOptions("render_image_to_pdf/pdf_document.pdf") viewer.view(viewOptions) if __name__ == "__main__": render_image_to_pdf() ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "pdf_document.pdf" >}} ```text Binary file (PDF, 45 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-images/render_image_to_pdf/pdf_document.pdf) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Render an image to PDF](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-images/render-image-to-pdf.png) ## Convert images to 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 an image to PNG. Use the [PngViewOptions.height](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/#properties) and [PngViewOptions.width](.height](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/pngviewoptions/#properties)) methods 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_image_to_png(): # Load image with Viewer("vector-image.svg") as viewer: # Create a PNG image. viewOptions = PngViewOptions("render_image_to_png/image.png") # Set width and height. viewOptions.width = 950 viewOptions.height = 550 viewer.view(viewOptions) if __name__ == "__main__": render_image_to_png() ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "image.png" >}} ```text Binary file (PNG, 179 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-images/render_image_to_png/image.png) {{< /tab >}} {{< /tabs >}} The following image demonstrates the result: ![Render an image to PNG](https://docs.groupdocs.com/viewer/python-net/images/rendering-basics/render-images/render-image-to-png.png) ## Convert images to 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 an image 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) methods 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_image_to_jpg(): # Load image with Viewer("vector-image.svg") as viewer: # Create a JPG image. viewOptions = JpgViewOptions("render_image_to_jpg/image_to_jpg.jpg") # Set width and height. viewOptions.width = 950 viewOptions.height = 550 viewer.view(viewOptions) if __name__ == "__main__": render_image_to_jpg() ``` {{< /tab >}} {{< tab "vector-image.svg" >}} {{< tab-text >}} `vector-image.svg` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-images/vector-image.svg) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "image_to_jpg.jpg" >}} ```text Binary file (JPG, 93 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-images/render_image_to_jpg/image_to_jpg.jpg) {{< /tab >}} {{< /tabs >}} ## Render a PSD file with custom fonts When you render a PSD file with custom fonts, you can specify a folder that contains necessary fonts to prevent font substitution during rendering. To do this, follow the steps below: 1. Create a [FolderFontSource](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.fonts/folderfontsource/) class instance and specify a path to the folder that stores custom fonts. Pass a [SearchOption](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.fonts/folderfontsource/#properties) enumeration member to the class constructor to define the search scope. The following options are available: * `TOP_FOLDER_ONLY`---Searches for the fonts only in the current folder. * `ALL_FOLDERS`---Searches for the fonts in the current folder and its subfolders. 2. Call the [FontSettings.set_font_sources](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.fonts/fontsettings/#methods) static method and pass the specified font source to this method as a parameter. This method allows you to specify multiple font sources. You can also use the [ViewOptions.default_font_name](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer.options/viewoptions/) method to specify the default font that should be used when a particular font is not found. {{< tabs "example6">}} {{< tab "Python" >}} ```python import os from groupdocs.viewer import Viewer from groupdocs.viewer.fonts import FolderFontSource, SearchOption, FontSettings from groupdocs.viewer.options import JpgViewOptions def render_psd_with_custom_fonts(): # Create font sources. os.makedirs("./custom_fonts_folder", exist_ok=True) os.makedirs("./custom_additional_fonts_folder", exist_ok=True) # Add custom fonts folder to look for fonts recursively. (look into subfolders too). folderFontSource = [FolderFontSource("./custom_fonts_folder", SearchOption.ALL_FOLDERS)] # Add custom fonts folder to look for fonts only in this folder (without subfolders). additionalFontSource = [FolderFontSource("./custom_additional_fonts_folder", SearchOption.TOP_FOLDER_ONLY)] # Call SetFontSources method and supply font sources as arguments. FontSettings.set_font_sources(folderFontSource, additionalFontSource) try: # Load PSD file with Viewer("sample.psd") as viewer: # Create a JPG image. viewOptions = JpgViewOptions("render_psd_with_custom_fonts/psd_with_custom_fonts.jpg") viewOptions.default_font_name = "Arial" viewer.view(viewOptions) finally: # Reset FontSettings so the registered folders don't leak into # subsequent rendering calls in the same process. FontSettings.reset_font_sources() if __name__ == "__main__": render_psd_with_custom_fonts() ``` {{< /tab >}} {{< tab "sample.psd" >}} {{< tab-text >}} `sample.psd` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-images/sample.psd) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "psd_with_custom_fonts.jpg" >}} ```text Binary file (JPG, 25 KB) ``` [Download full output](https://docs.groupdocs.com/viewer/python-net/_output_files/rendering-basics/render-images/render_psd_with_custom_fonts/psd_with_custom_fonts.jpg) {{< /tab >}} {{< /tabs >}} --- ## Render email messages as HTML, PDF, PNG, and JPEG files Path: https://docs.groupdocs.com/viewer/python-net/render-email-messages/ [GroupDocs.Viewer for Python via .NET](https://products.groupdocs.com/viewer/python-net) allows you to render your email messages in HTML, PDF, PNG, and JPEG formats. You do not need to use third-party email clients to view the contents of email files within your .NET application (web or desktop). To start with the GroupDocs.Viewer API, create a [Viewer](https://reference.groupdocs.com/viewer/python-net/groupdocs.viewer/viewer) class instance. Pass an email message you want to view to the class constructor. You can load the message 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 loaded message to HTML, PDF, or image format. These methods allow you to render the entire message or specific pages. {{< button style="primary" link="https://products.groupdocs.app/viewer/email" >}} {{< icon "gdoc_person" >}} View email 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 email file formats GroupDocs.Viewer supports the following email file formats: * [Email Message](https://docs.fileformat.com/email/eml) (.EML) * [Apple Mail Message](https://docs.fileformat.com/email/emlx) (.EMLX) * [Email Mailbox File](https://docs.fileformat.com/email/mbox/) (.MBOX) * [Outlook Message Item File](https://docs.fileformat.com/email/msg) (.MSG) * [vCard (Virtual Contact) File](https://docs.fileformat.com/email/vcf/) (.VCF, .VCARD) GroupDocs.Viewer can detect the email file format automatically based on information in the file header. ## Render email messages 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 an email message to HTML. 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 exclude specific fonts. 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 embed an email message in an HTML page, 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_email_to_html(): # Load email message with Viewer("sample.eml") as viewer: # Create an HTML file. viewOptions = HtmlViewOptions.for_embedded_resources("render_email_to_html/pdf_page_{0}.html") viewer.view(viewOptions) if __name__ == "__main__": render_email_to_html() ``` {{< /tab >}} {{< tab "sample.eml" >}} {{< tab-text >}} `sample.eml` is the sample file used in this example. Click [here](https://docs.groupdocs.com/viewer/python-net/_sample_files/rendering-basics/render-email-messages/sample.eml) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "pdf_page_1.html" >}} ```text