Weasyprint support

Created on 15 January 2019, almost 6 years ago
Updated 22 July 2024, 5 months ago

WKHTMLTOPDF is pretty much the most versatile library out there. However, I find it a bit limited when you need to make advanced customization.

So I looked for something else that could cover all of my requirements (header, footer, page#, TOC, Frontpate, SVG, custom fonts) and found weasyprint. It seems to be exactly what I was looking for, but it's not very php oriented. In fact it's pretty much like WKHTMLTOPDF, that is coded in c++.

Hopefully, there's PHP_WKHTMLTOPDF for that, but a PHP_WEASYPRINT library would be very useful too.

Anyhow, I don't have a solution, I just wanted to propose this alternative. Thanks.

✨ Feature request
Status

RTBC

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada JFKiwad Montreal

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !28Issue #3026158: Weasyprint support β†’ (Open) created by kitikonti
  • First commit to issue fork.
  • Pipeline finished with Success
    9 months ago
    Total: 224s
    #126679
  • Status changed to RTBC 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    Rebased to get CI working. Just tried and it worked great!

  • πŸ‡ΊπŸ‡ΈUnited States freelock Seattle

    Great to hear this is working!

    I subscribed to this case looking for more modern CSS support than was available in wkhtmltopdf, and thought WeasyPrint might be a good option. However, since then we've started using headless Chrome, which has fairly decent PDF support.

    And there is now an entity_print_chrome module β†’ , which has basic functionality working, with the chrome_pdf library.

    So now I'm wondering: Should WeasyPrint go into another module, and this module just needs some pointers to the other entity print plugins available?

    Or should entity_print_chrome get pulled into this module as a submodule?

    I think the big issue here is discoverability -- it took quite some digging to find entity_print_chrome, and I think it should have more visibility, along with WeasyPrint.

    If Weasyprint is added to the existing module, will anyone notice and discover it? I'm thinking it will be more noticeable on the project page for entity print...

  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    I didn't know about entity_print_chrome until your comment, and I only found out about Weasyprint sort of by accident the other day and was pleased to find a patch to enable it in entity_print. Its output is significantly better than several of the other PDF engines I've tried!

  • πŸ‡¬πŸ‡§United Kingdom matt b

    Just patched using https://git.drupalcode.org/project/entity_print/-/merge_requests/28.patch which applied fine.

    At /admin/config/content/entityprint, I get the message
    Php Weasyprint is not available because it is not configured. Please install with: composer require "pontedilana/php-weasyprint".

    Install weasyprint via composer, check it's installed (it's in the vendor directory), reload /admin/config/content/entityprint and I still get the message (and can't select weasyprint as an engine)

  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    Did a cache clear help?

  • πŸ‡¬πŸ‡§United Kingdom matt b

    No it didn't. I just tried to add Wkhtmltopdf as well. Composer installs it fine, but even after a cache rebuild I still have the message that this also is not available. It may be my local enviroment, so I'll keep checking, as this is probably a separate issue.

    +1 for separate modules for PDF engines!

  • πŸ‡¬πŸ‡§United Kingdom matt b
  • πŸ‡¬πŸ‡§United Kingdom matt b

    pushed to the next environment and it works fine there! Now I get "The weasyprint binary does not exist at /usr/local/bin/weasyprint"
    (also tried /usr/bin/weasyprint). WKHTMLTOPDF is in /usr/local/bin/ so I need to see if I can find the binary on the hosted enviroment or if I've missed a step.

  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    My production settings is setting $config['entity_print.print_engine.phpwkhtmltopdf']['settings']['binary_location'] because I needed to install it with pyenv.

  • πŸ‡¬πŸ‡§United Kingdom matt b

    So my host (pantheon) won't allow additional binaries to be installed, although they do have WKHTMLTOPDF which is fine but not going to work for me, which means my weasyprint journey ends here. I can either move host or pay for a 3rd party pdf service as none of the entity_print engines work for me.

Production build 0.71.5 2024