html4pdf vs ReportLab

ReportLab has been the serious answer in Python for twenty years, and it is still excellent. The comparison is not about quality, it is about who edits the layout.

The short answer

ReportLab is the right tool when the document is a fixed, precise artefact and you want no dependencies. It is the wrong tool when the design changes often, because every change is a code change.

What ReportLab is

ReportLab builds PDFs programmatically: you place text, lines, tables and images with a drawing API, or compose a document with its Platypus layout engine. Output is exact, it is fast, it has no system dependencies, and the open source version is widely used in production. It does not take HTML.

Side by side

 ReportLabhtml4pdf
What you writePython: canvases, flowables, stylesThe HTML and CSS you already have
PrecisionAbsolute, you place everythingWhatever the browser lays out
Who can change the designA Python developerAnyone who can edit a template
HTML inputNoYes
ChartsIts own charting libraryAny JavaScript chart library
DependenciesNone beyond pipAn HTTPS call
SpeedVery fastThree to five seconds including the round trip
CostFreeFrom $0.033 per document

Choose ReportLab when

  • The layout is fixed, precise and rarely changes: labels, certificates, regulated forms.
  • You need exact control over position, down to the point.
  • Nothing may leave the process, and no new dependency is acceptable.
  • Volume is high and the document is simple.

Choose html4pdf when

  • The document already exists as a web page and should look like it.
  • The design changes often, and each change currently means a pull request.
  • Someone other than a developer should be able to edit the template.
  • The page needs a chart or a layout that would take a day to draw by hand.

See the code

The working example, in the language this decision is being made in.

ReportLab: common questions

Can ReportLab convert HTML to PDF?

Not directly. It draws documents from code. Projects like xhtml2pdf put a small HTML layer on top of it, but that layer implements its own limited CSS rather than acting as a browser.

ReportLab or WeasyPrint?

WeasyPrint if your document is already HTML and CSS without scripts. ReportLab if you want to build the document in Python with exact control and no markup involved.

Is ReportLab free?

The open source library is, under a permissive licence, and it is what most projects use. There is also a commercial product built on top of it.

Which is faster?

ReportLab, comfortably. It is drawing directly rather than laying out a page in a browser, with no network involved.

Try it before you decide

New accounts get 10 free credits, no card. Send the HTML you already have and compare the output against whatever you are using now.

Get API key

Other comparisons