Live data from Hacker News

Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

github.com

41–50 of 51 posts

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#41

Maybe this isn't the same but it's a relatively few lines of code to use puppeteer to use an actual browser to render pages to PDFs/PNGs. Advantages would be everything is supported. Every new feature in CSS, HTML, SVG, Canvas2D, WebGL, WebGPU, etc... (though for WebGL/WebGPU you might need to pass in some flags to use llvmpipe/mesa/warp etc... Asking your favorite LLM will give you da codez PS: I'm not trying to dis…

That’s a good point. Using Puppeteer or a headless browser gives you essentially full web platform support. The tradeoff is that it comes with a heavier runtime and more moving parts (Chromium, Node, etc.). PlutoPrint aims to be much lighter: no browser dependency, just a compact C++ engine with a Python wrapper. It does not cover the entire browser feature set but it is fast, portable, and easy to drop into projects…

I did this for a project recently, using Firefox and Selenium. It totally worked, but was very heavy on the dependencies and felt very clumsy.

This is exactly what I was looking for a few months ago. I might revisit that project with it.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#42
post #21

This isn't theoretical. In my 20 years in retail and logistics, I've seen these libraries repeatedly fail in production. Real world examples include: * Invoices: Totals get pushed to a new page with no repeated header. This is a classic failure of CSS table rendering across page breaks. properties like page-break-inside: avoid are notoriously inconsistent in browser print to PDF engines. Line items get split mid row…

Have you looked at something like Latex or Typst? They come with their own layout engine, so potentially less tedious work like specifying exact positions.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#43
post #17

Earlier quoted context omitted.

It should be required to run these tests for these libraries. It's really frustrating to have to discover it trying to make it work.

CSS coverage is stated in [1]. It should be required to do minimal assessment before entitledly posting on HN. [1]: https://github.com/plutoprint/plutobook/blob/main/FEATURES.m...

I'm not sure your point. CSS print conformance is extremely complex. There is a fairly well known open source test suite, that's fully dynamic, that can be run with visual outputs, fail/pass metrics etc. That would give an interested new user a much better grounding if the library is worth using, considering there are already several other options.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#44
post #8

It would be great if you could run it against the tests at https://www.print-css.rocks/ They would give a much better idea of its complex printing capabilities.

I'm surprised to see the properties I'm most interested in neither in these tests nor in plutoprints supported css. I'm talking about `text-wrap: pretty` (potentially avoid rivers and orpahns, depending on implementation), `orphans`, `widows` and the various `break-`.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#45
Hi Samuel,

Building a rendering HTML/CSS rendering engine is no easy job. Congratulations! I'm curious how were you able to pull this off? What documentations were helpful and what was your inspiration? I'm in awe and wat to learn more about this initiative.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#46

Hi Samuel, Building a rendering HTML/CSS rendering engine is no easy job. Congratulations! I'm curious how were you able to pull this off? What documentations were helpful and what was your inspiration? I'm in awe and wat to learn more about this initiative.

Thank you for your kind words and for noticing the work behind this. Building an HTML and CSS rendering engine has been a long journey with many surprises. I have been maintaining https://github.com/sammycage/lunasvg for years, so I was familiar with interpreting specs and rendering engines. That experience gave me the confidence to tackle HTML.

At first, my plan was simple. I wanted to make an HTML rendering library. But soon, I realized it could be even more useful if it focused on paged output so I could make PDFs directly. C and C++ do not have an HTML-to-PDF library that is not a full web engine. I started coding and thought I could finish in a year by working a few hours each day. But reality came fast. HTML and CSS are much harder than SVG, and even small things caused big problems.

I studied KHTML and WebKit to see how real HTML and CSS engines work. The official specs were very helpful. Slowly, everything started to come together. It felt like discovering a hidden world behind the web pages we see every day.

The hardest part has been TableLayout. Tables look simple, but handling row and column spans, nested tables, alignment, page breaks, and box calculations was very hard. I spent many hours fixing layout bugs that only appeared in some situations. It was frustrating, humbling, and also very satisfying when it worked.

I am still learning and improving. I hope other people enjoy PlutoPrint and PlutoBook as much as I do.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#47

Hi Samuel, Building a rendering HTML/CSS rendering engine is no easy job. Congratulations! I'm curious how were you able to pull this off? What documentations were helpful and what was your inspiration? I'm in awe and wat to learn more about this initiative.

Thank you for your kind words and for noticing the work behind this. Building an HTML and CSS rendering engine has been a long journey with many surprises. I have been maintaining https://github.com/sammycage/lunasvg for years, so I was familiar with interpreting specs and rendering engines. That experience gave me the confidence to tackle HTML. At first, my plan was simple. I wanted to make an HTML rendering library…

Sounds like a wild ride! Thanks for making this open-source.

Quick question:

1. I see you've hand-written parsers yourself both css & html, why not use existing parsers? was minimizing dependencies one of your goals?

2. Does the project recongnize headers / footers and other such @page css rules?

3. Fragmentation(pagination) logic has a huge set of challenges (at least from what I read about Chrome implementing fragmentation) - did you come across this? - https://developer.chrome.com/docs/chromium/renderingng-fragm....

Was fragmentation logic really that difficult to implement?

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#48

Earlier quoted context omitted.

Thank you for your kind words and for noticing the work behind this. Building an HTML and CSS rendering engine has been a long journey with many surprises. I have been maintaining https://github.com/sammycage/lunasvg for years, so I was familiar with interpreting specs and rendering engines. That experience gave me the confidence to tackle HTML. At first, my plan was simple. I wanted to make an HTML rendering library…

Sounds like a wild ride! Thanks for making this open-source. Quick question: 1. I see you've hand-written parsers yourself both css & html, why not use existing parsers? was minimizing dependencies one of your goals? 2. Does the project recongnize headers / footers and other such @page css rules? 3. Fragmentation(pagination) logic has a huge set of challenges (at least from what I read about Chrome implementing fragm…

Thanks for your questions!

1. The documentation for HTML and CSS parsers is pretty straightforward and easier to implement, so I thought it was better to write them myself.

2. It fully supports margin boxes (headers and footers) using properties like @top-left and @bottom-center inside @page rules. You can see more here: https://github.com/plutoprint/plutobook/blob/main/FEATURES.m...

3. Yes, I did come across this. Fragmentation logic is as difficult as it sounds. Right now PlutoBook works with a single, consistent page size throughout a document and does not support named pages, which simplifies things a lot.

Feel free to contact me via email if you have more questions.

Re: Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python

#49

Maybe this isn't the same but it's a relatively few lines of code to use puppeteer to use an actual browser to render pages to PDFs/PNGs. Advantages would be everything is supported. Every new feature in CSS, HTML, SVG, Canvas2D, WebGL, WebGPU, etc... (though for WebGL/WebGPU you might need to pass in some flags to use llvmpipe/mesa/warp etc... Asking your favorite LLM will give you da codez PS: I'm not trying to dis…

Gotenberg[0] wraps up Chromium nicely for this purpose. However, at scale, spinning up Chromium for each PDF you want to generate is painful. I'd definitely consider a solution like PlutoPrint.

0: https://gotenberg.dev/

Post reply on HN