Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to replace xhtml2pdf with pywkhtmltopdf #298

Open
sjkingo opened this issue Jun 29, 2016 · 0 comments
Open

Proposal to replace xhtml2pdf with pywkhtmltopdf #298

sjkingo opened this issue Jun 29, 2016 · 0 comments

Comments

@sjkingo
Copy link
Contributor

sjkingo commented Jun 29, 2016

Currently we use xhtml2pdf.pisa to generate the PDF invoice in cartridge/shop/views.py#L391.

This has many drawbacks:

  • no proper support for Python 3 (the developers seem unwilling to work with anyone on this)
  • requires a long list of C dependencies (including reportlab)
  • broken support for using many features of HTML/CSS such as images and links
  • once you get around all of the above, the resulting PDF typically isn't an accurate conversion of the input

wkhtmltopdf is a command-line application for generating PDFs off HTML pages, and supports a wide range of features that would be useful for Cartridge users. It uses the excellent WebKit browser engine for rendering.

I propose switching to my Python wrapper around wkhtmltopdf, pywkhtmltopdf. The code changes would be minimal and users could immediately start using more advanced features of HTML/CSS in the invoice template than they could before. Existing templates should work fine, though the specific layout and fonts may change slightly with the change in rendering engine.

Some work still needs to be done to pywkhtmltopdf - namely a test suite. I have opened an issue for that at sjkingo/pywkhtmltopdf#1 and should be able to knock that over in the next day or two.

One question comes to mind: since the library depends on a static binary that needs to be downloaded and installed somewhere on the PATH, how should we handle this initial setup? It would be best if the user has to do nothing - perhaps the setup.py script in pywkhtmltopdf can do this on install of the library? Obviously would need to ensure the correct binary is downloaded (Linux/Darwin/Windows, x86/x86_64 etc), but I'm sure some logic using import platform should be able to handle this.

What are your thoughts @stephenmcd?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant