software · Q1453
xhtml2pdf
Python HTML-to-PDF converter built on ReportLab with page templates, frames and resource-access policies.
Overview
xhtml2pdf converts HTML and supported CSS into PDFs using Python and the ReportLab toolkit, with pypdf among its dependencies. It provides a Python interface and command-line entry points for template-driven document generation. Its page-and-frame model and renderer-specific controls mean that browser layout compatibility must be assessed rather than assumed.[1][2][5]
Page templates and flowing content
A page template defines dimensions and orientation, while rectangular frames define where content is placed. Content frames carry flowing HTML across the document; static frames supply recurring items such as headers and footers. The manual explicitly says that a CSS page-name property used by other engines does not select templates here. xhtml2pdf uses its own template-switching mechanisms, making this a practical migration issue.[2]
Tables and form behavior
The reference recommends explicit table widths and documents constrained handling for cells taller than the available space. A configured policy may shrink, truncate, overflow or reject such content, so table output should be checked with long real data. The form interface also has limits: named supported controls become PDF fields, but radio inputs are merely drawn, and choice options cannot separate a stored value from their label.[3]
Resource access and incomplete output
Resource restrictions depend on the entry point. The Python rendering policy normally blocks internal network addresses and local files outside the permitted directory. For a named command-line document, network restrictions still apply, but local-file confinement requires --resource-root. A denied asset is logged and omitted while rendering continues, so inspect warnings and output for missing stylesheets, fonts and images. The link callback rewrites locations; the resource policy controls access. The documentation also recommends an explicit allowed-host policy for untrusted input because an address check alone does not close DNS-rebinding risks.[4]
Deployment limits and licensing
The package requires Python 3.10 or later and includes ReportLab and other parsing, imaging and PDF dependencies. Apache-2.0 licensing applies to xhtml2pdf, while dependencies retain their own terms. Resource-access controls also do not bound conversion time or total memory use: the security guidance still calls for limits around untrusted work. This article reports those documented boundaries without claiming a tested secure deployment.[4][5][6]
Substitution considerations
xhtml2pdf can substitute for WeasyPrint when the required output is a PDF from compatible HTML templates. Both support Python workflows, but xhtml2pdf's frame model and renderer-specific controls can require template changes. Confirm recurring content, long tables and form behavior before switching; a shared HTML input format does not establish identical pagination or complete browser-CSS support.[1][2][3][7]
Capabilities & limitations
Page templates and frames
supportedContent flows through rectangular content frames; static frames provide recurring content.[2]
Python HTML-template PDF generation · Python 3.10+; dependencies vary by platform · Version, build and integration requirements apply
1 source · check evidence
Content/static frames and unsupported CSS page property
vendor · checked 2026-10-07Interactive form controls
limitedSupported named controls become PDF fields; radio inputs are drawn without an interactive radio group.[3]
Python HTML-template PDF generation · Python 3.10+; dependencies vary by platform · Version, build and integration requirements apply
1 source · check evidence
Tables, long-cell handling and PDF form limitations
vendor · checked 2026-10-07Denied-resource handling
limitedDenied assets are warned about and omitted while rendering continues; successful completion need not mean every asset loaded.[4]
Python HTML-template PDF generation · Python 3.10+; dependencies vary by platform · Version, build and integration requirements apply
1 source · check evidence
Default resource policy, skipped denied assets and resource exhaustion
vendor · checked 2026-10-07Can substitute for
These are products or services this entry can replace. Check the task and limitations for each comparison.
WeasyPrint for Python HTML-template PDF generation
limitedCan cover compatible HTML-template PDF generation in Python, with different page-template syntax and layout limits.[1][2][7]
Python 3.10+; dependencies vary by platform · Version, build and integration requirements apply
References
- xhtml2pdf documentation
HTML/CSS conversion, Python and CLI interfaces
vendor · retrieved 2026-10-07 - xhtml2pdf page layout
Content/static frames and unsupported CSS page property
vendor · retrieved 2026-10-07 - xhtml2pdf reference
Tables, long-cell handling and PDF form limitations
vendor · retrieved 2026-10-07 - xhtml2pdf resource security
Default resource policy, skipped denied assets and resource exhaustion
vendor · retrieved 2026-10-07 - xhtml2pdf package metadata
Python 3.10+, dependencies and command-line entry points
vendor · retrieved 2026-10-07 - xhtml2pdf license
Apache License Version 2.0
vendor · retrieved 2026-10-07 - WeasyPrint documentation
HTML/CSS pagination engine
vendor · retrieved 2026-10-07 - https://xhtml2pdf.readthedocs.io/en/latest/security.html
What is refused by default; Choosing your own policy; On the command line; link_callback warning.
vendor · retrieved 2026-10-07
Discussion & disputes
Ask about unclear claims or explain a concern with supporting sources. If you have a specific fix, suggest a correction.
No discussion yet.
Revision history
Open a revision to read an earlier version of this article.
| Revision | Timestamp | Edit summary |
|---|---|---|
| 1533 | 2026-10-19 11:06:04 | /* wbeditentity-create-item:0| */ sf:9862f0ea-4577-450b-8e73-b452a9ead952:v2 | Qualify resource restrictions by entry point: Python rendering policy versus CLI local-file confinement with --resource-root. Preserve omitted-resource behavior | attribution: /proposals/9862f0ea-4577-450b-8e73-b452a9ead952 |