Package: zipreport-lib
ZipReportTransform 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 thisexample!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 browser-generated JS content (with zipreport-server);Support for headers, page numbers and ToC (usingPagedJS, see details below);Requirements:Python >= 3.8Jinja2 >= 3.1Compatible backend for pdf generation (zipreport-server, xhtmltopdf, or WeasyPrint);v2.x.x breaking changesStarting with zipreport 2.0.0, support for the electron-based zipreport-cli rendering backend is removed; using
azipreport-serverversion 2.0.0 or later - preferably using a docker container,
is now the recommended approach.The behavior of the JS event approach has also changed; PDF rendering can now be triggered via console message,
instead of dispatching an event.If you use JS events to trigger rendering, you need to update your templates.Old method:(...)// signal PDF generation after all DOM changes are performeddocument.dispatchEvent(newEvent('zpt-view-ready'))(...)New method, starting with v2.0.0:(...)// signal PDF generation after all DOM changes are performedconsole.log('zpt-view-ready')(...)InstallationInstalling via pip:$pipinstallzipreport-libTL;DR; exampleUsing zipreport-cli backend to render a report file:fromzipreportimportZipReportfromzipreport.reportimportReportFileLoader# existing zpt templatereport_file="report.zpt"# output fileoutput_file="result.pdf"# template variablesreport_data={'title':"Example report using Jinja templating",'color_list':['red','blue','green'],'description':'a long text field with some filler description',}# load report from filezpt=ReportFileLoader.load(report_file)# initialize api clientclient=ZipReport("https://127.0.0.1:6543","secretKey")job=client.create_job(zpt)# generate a PDF by calling the processor, using the API client# this method returns a JobResultresult=client.render(job,report_data)# if PDF generation was successful, save to fileifresult.success:withopen(output_file,'wb')asrpt:rpt.write(result.report.read())Paged.jsPagedJSis 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.To use PagedJS capabilities,zipreport-servermust be used as a backend.Available backendsZipreport-Serverzipreport-serveris a headless browser daemon orchestrator, designed specifically to work with ZipReport. It can be
either installed locally or run via docker.zipreport-server is the only supported backend that enables full usage of client-side JavaScript and leveraging the PagedJS
capabilities.WeasyPrintThis backend is provided for compatibility. For new projects, please use zipreport-server.WeasyPrintis a popular Python library to generate PDFs from HTML. It doesn't support JavaScript,
and CSS is limited.DocumentationDetailed documentation on usage and report building is available on theproject documentation.