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]
Contents 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]
Also included: 3 capabilities and 0 substitute relationships. Check substitutes in section 1 and capabilities in section 3.