Skip to main content

Python HTML to PDF reporting engine

Project description

ZipReport

Tests docs pypi license

Transform HTML templates into beautiful PDF or MIME reports, with full CSS and client Javascript support, under a permissive license.

Want to see it in action? Check this example!

Highlights:

  • Create your reports using Jinja templates;
  • Dynamic image support (embedding of runtime-generated images);
  • Reports are packed in a single file for easy distribution or bundling;
  • Optional MIME processor to embed resources in a single email message;
  • Support for generated JS content (with zipreport-server or zipreport-cli);
  • Support for headers, page numbers and ToC (via PagedJS, see below);

Requirements:

  • Python >= 3.6
  • Jinja2 >= 2.11 && < 3.1
  • Compatible backend for pdf generation (zipreport-server, zipreport-cli, xhtmltopdf, or WeasyPrint);

Installation

Installing via pip:

$ pip install zipreport-lib
Quick example

Using zipreport-cli backend to render a report file:

from zipreport import ZipReportCli
from zipreport.report import ReportFileLoader

# path to zipreport-cli binary
cli_path = "/opt/zpt-cli/zpt-cli"

# output file
output_file = "result.pdf"

# template variables to be used for rendering
report_data = {
	'title': "Example report using Jinja templating",
	'color_list': ['red', 'blue', 'green'],
	'description': 'a long text field with some filler description so the page isn\'t that empty',
}

# load zpt report file
zpt = ReportFileLoader.load("reports/simple.zpt")

# render the report with default job options
result = ZipReportCli(cli_path).render_defaults(zpt, report_data)

if result.success:
	# write output file
	with open(output_file, 'wb') as rpt:
		rpt.write(result.report.read())

Paged.js

Paged.js is an amazing javascript library that performs pagination of HTML documents for print, under MIT license. It acts as polyfill for W3C specification for print, and allows the creation of headers, footers, page numbers, table of contents, etc. in the browser.

Available backends

zipreport-server/zipreport-cli

This is the recommended backend to use, that enables full usage of client-side JavaScript and leveraging the Paged.js capabilities.

zipreport-cli is an electron-based command-line utility used to convert webpages to PDF.

zipreport-server is a daemon that allows the usage of zipreport-cli via API.

WeasyPrint

This backend is provided for compatibility. For new projects, please use zipreport-cli or zipreport-server.

WeasyPrint is a popular Python library to generate PDFs from HTML. It doesn't support JavaScript, and CSS is limited.

wkhtmltopdf

This backend is provided for compatibility. While it supports some JavaScript, it's not able to run Paged.js.

Wkhtmltopdf is a binary utility based on QtWebKit to generate PDF files from HTML pages. While it features some JavaScript and CSS support, the underlying library is obsolete.

Documentation

Detailed documentation on usage and report building is available on the project documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zipreport-lib-0.9.5.tar.gz (42.6 kB view hashes)

Uploaded Source

Built Distribution

zipreport_lib-0.9.5-py3-none-any.whl (55.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page