Skip to content

Add chromedp PDF converter#33

Open
fabian-z wants to merge 1 commit intoinvopop:mainfrom
fabian-z:pdf-chromedp
Open

Add chromedp PDF converter#33
fabian-z wants to merge 1 commit intoinvopop:mainfrom
fabian-z:pdf-chromedp

Conversation

@fabian-z
Copy link

This PR adds chromedp as a new PDF conversion driver alongside the existing Gotenberg and WeasyPrint options.
Key benefits:

  • Runs without requiring an external server (automatically finding an installed Chrome / Chromium)
  • Operates in headless mode
  • Supports modern web standards through Chrome's rendering engine
  • 30-second timeout protection by default
  • Preserves CSS page styling with PreferCSSPageSize
    • This lead to better results in testing than with Gotenberg (e.g. A4 page size with default template)

The implementation handles page loading events efficiently and provides clear error messages to the caller for debugging potential issues.
Looking forward to your feedback!

@samlown
Copy link
Contributor

samlown commented Feb 13, 2025

Hi @fabian-z! Many thanks for this PR. This does indeed seem like a better approach compared to Gotenberg. When we tested Chromium PDFs previously we had lots of problems with headers/footers and pagination, but I'll give this a try locally and see how it compares to Prince (our preferred option).

@fabian-z
Copy link
Author

Thanks for the feedback! I understand the difficulties and if you have any problematic examples, please feel free to share them with me, will be glad to take a look :) My initial results were comparable with Gotenberg, which also uses Chromium.

Prince indeed seems to have several benefits, but for certain scenarios it makes sense to have a "good enough" and Open Source solution available. In my case, this is due to post processing the PDF with Ghostscript to produce a valid PDF/A-3 hybrid electronic invoice with embedded EN16931 XML.

@samlown
Copy link
Contributor

samlown commented Feb 13, 2025 via email

@fabian-z
Copy link
Author

fabian-z commented Feb 14, 2025

Thanks for the pointer to akretion/factur-x, that and the underlying pypdf look very interesting. Will definitely give the library a try. For the moment, I solved the problem directly with Ghostscript, building a solution in PostScript (including XMP) which has the advantage of ensuring PDF/A compliance by built-in validation.. Let me know if that may be interesting for you as well :)

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

Successfully merging this pull request may close these issues.

2 participants