Render to PDF

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

When rendering to PDF, GroupDocs.Viewer renders all pages of the source document as a single PDF document.

To render files to PDF, follow these steps:

  1. Create an instance of the Viewer class. Specify the source document path as a constructor parameter.
  2. Instantiate the PdfViewOptions object. Specify a path to save the rendered file.
  3. Call the View.view() method of the Viewer object. Specify the PdfViewOptions object as the parameter.

The following code snippet shows how to render a .docx document to PDF:

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions

def render_to_pdf():
    # Load document
    with Viewer("sample.docx") as viewer:
        pdf_options = PdfViewOptions("output-to-pdf.pdf")
        viewer.view(pdf_options)

    print(f"\nSource document rendered successfully.")

if __name__ == "__main__":
    render_to_pdf()

sample.docx is the sample file used in this example. Click here to download it.

Binary file (PDF, 719 KB)

Download full output

For details, please refer to the following pages: