Nutrient Python SDK
Need pricing or implementation help? Talk to Sales.
HTML-TO-PDF CONVERSION
from nutrient_sdk import Documentfrom nutrient_sdk import NutrientException
def main(): try: with Document.open("input.html") as document: document.export_as_pdf("output.pdf") print("Successfully converted to output.pdf") except NutrientException as e: print(f"Error: {e}")
if __name__ == "__main__": main()USE CASES
Render an HTML invoice or receipt template — styled with your own CSS — into a fixed PDF for emailing, billing, and record keeping.
Turn dashboards, statements, and generated reports built as HTML into print-ready PDFs with consistent pagination and layout.
Capture rendered webpages as PDFs for offline access, audit trails, and long-term archiving where a stable format is required.
Nutrient renders HTML through Chrome, so fonts, images, and CSS styling come through exactly as they appear in the browser.
Convert Markdown to PDF in Python. The SDK parses Markdown and renders formatted PDF output.
export_as_pdf()Convert DOCX to PDF in Python. The SDK renders Word documents to PDF with no Microsoft Office required.
export_as_pdf()Convert XLSX to PDF in Python. The SDK renders spreadsheets to PDF for sharing and archiving.
export_as_pdf()ADVANCED CAPABILITIES
The SDK handles more than one-off conversions. Build HTML-to-PDF conversion into automated workflows and deploy anywhere Python runs.
HTML is rendered through Chrome, so complex CSS, web fonts, and images appear in the PDF exactly as they do in the browser.
Convert many HTML files in a loop or with Python’s concurrency tools. Each conversion follows the same pattern: open and export.
No GUI dependencies — run HTML-to-PDF conversion in background jobs, cron tasks, or API handlers on any server.
Run conversions in containers by including Chrome in the image and running as a non-root user, following the Docker deployment guide.
Install Nutrient Python SDK. Then open your HTML file with Document.open('input.html') and call document.export_as_pdf('output.pdf'). The SDK renders the HTML through Chrome and writes a PDF that preserves the page’s layout, fonts, images, and CSS. See the HTML-to-PDF guide for a complete working example.
Yes. Nutrient renders HTML through Chrome, so CSS, web fonts, images, and page layout come through in the PDF exactly as they appear in the browser. You don’t need to implement any rendering or pagination logic yourself.
No template engine or browser-automation framework is required in your code — the conversion is a single export_as_pdf() call. The SDK uses Chrome internally for rendering; on first run, it provisions the rendering engine for you.
Yes. The SDK is server-ready and runs on Linux. Because HTML rendering relies on Chrome, a containerized deployment needs Chrome included in the image and the container run as a non-root user. See the guide on Chrome-based conversions in Docker for the packaged setup.
Loop over your HTML files, or use Python’s concurrency tools, and run the same two-step conversion for each one: Document.open(...) then export_as_pdf(...). Because there are no GUI dependencies, the same code runs in background jobs and CI/CD pipelines.
Yes. The open-then-export pattern is the same across formats. Use export_as_pdf() after opening Markdown, Word (DOCX), Excel (XLSX), or PowerPoint (PPTX). See the Python conversion guides for each format.
Wrap the conversion in a try-except block and catch NutrientException for SDK-specific errors. Use the context manager syntax (with Document.open(...) as document:) so the document is closed automatically, even when an error occurs.
FREE TRIAL
Start converting HTML to PDF in Python in minutes — no payment information required.
Also available for
More Python SDK capabilities