# xhtml2pdf

Python HTML\-to\-PDF converter built on ReportLab with page templates, frames and resource\-access policies\.

ID: Q1453 · Revision: 1533

Type: software · License: Apache\-2\.0[^license] · Status: active

Website: https://xhtml2pdf.readthedocs.io/



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\.[^home][^layout][^package]

## 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\.[^layout]

## 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\.[^reference]

## 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\.[^security]

## 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\.[^package][^license][^security]

## Substitution considerations

xhtml2pdf can substitute for [WeasyPrint](/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\.[^home][^layout][^reference][^weasy]

## Capabilities and substitutions

### Page templates and frames — supported

Content flows through rectangular content frames; static frames provide recurring content\.[^layout]

Use case: Python HTML\-template PDF generation · Platforms: Python 3\.10\+; dependencies vary by platform · Region: Version, build and integration requirements apply

### Interactive form controls — limited

Supported named controls become PDF fields; radio inputs are drawn without an interactive radio group\.[^reference]

Use case: Python HTML\-template PDF generation · Platforms: Python 3\.10\+; dependencies vary by platform · Region: Version, build and integration requirements apply

### Denied\-resource handling — limited

Denied assets are warned about and omitted while rendering continues; successful completion need not mean every asset loaded\.[^security]

Use case: Python HTML\-template PDF generation · Platforms: Python 3\.10\+; dependencies vary by platform · Region: Version, build and integration requirements apply

### [Substitute for WeasyPrint](/weasyprint) — limited

Can cover compatible HTML\-template PDF generation in Python, with different page\-template syntax and layout limits\.[^home][^layout][^weasy]

Use case: Python HTML\-template PDF generation · Platforms: Python 3\.10\+; dependencies vary by platform · Region: Version, build and integration requirements apply

## References

[^home]: [xhtml2pdf documentation](<https://xhtml2pdf.readthedocs.io/en/latest/>) — HTML/CSS conversion, Python and CLI interfaces (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^layout]: [xhtml2pdf page layout](<https://xhtml2pdf.readthedocs.io/en/latest/format_html.html>) — Content/static frames and unsupported CSS page property (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^reference]: [xhtml2pdf reference](<https://xhtml2pdf.readthedocs.io/en/latest/reference.html>) — Tables, long\-cell handling and PDF form limitations (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^security]: [xhtml2pdf resource security](<https://xhtml2pdf.readthedocs.io/en/latest/security.html>) — Default resource policy, skipped denied assets and resource exhaustion (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^package]: [xhtml2pdf package metadata](<https://github.com/xhtml2pdf/xhtml2pdf/blob/master/pyproject.toml>) — Python 3\.10\+, dependencies and command\-line entry points (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^license]: [xhtml2pdf license](<https://github.com/xhtml2pdf/xhtml2pdf/blob/master/LICENSE.txt>) — Apache License Version 2\.0 (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^weasy]: [WeasyPrint documentation](<https://doc.courtbouillon.org/weasyprint/stable/>) — HTML/CSS pagination engine (vendor; retrieved 2026-10-07T12:42:28.193Z)

[^source-8]: [https://xhtml2pdf\.readthedocs\.io/en/latest/security\.html](<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-07T12:42:28.193Z)

Source revision: https://substitutefor.net/entities/Q1453?revision=1533
