Readit News logoReadit News
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
lewisjoe · 4 months ago
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?

sammycage · 4 months ago
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.

sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
lewisjoe · 4 months ago
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.

sammycage · 4 months ago
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.

sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
_giorgio_ · 4 months ago
Hi, have you tested it with google colab notebooks?

Printing those things is really difficult. All the time I get split cells (with some rows not printed) and every kind of problems (like broken word wrap etc).

sammycage · 4 months ago
Hi! We haven’t specifically tested Colab notebooks. They’re tricky because of dynamic layouts and tables, but simpler notebook exports to HTML might work better. Any feedback or test cases would be super helpful to improve support.
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
iamgopal · 4 months ago
Comparing it to typst ?
sammycage · 4 months ago
Typst and PlutoPrint serve somewhat different purposes. Typst is more like a modern typesetting language, focusing on fully programmatic document layouts with its own syntax, while PlutoPrint is a Python library built on a C++ rendering engine that converts HTML or XML into PDFs and PNGs. PlutoPrint’s strengths are fast rendering, strong SVG support, and integration with existing Python workflows, whereas Typst is great if you want a typesetting DSL with precise layout control from the ground up.
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
richfreedman · 4 months ago
Nice! I think that it would be great if this could take markdown as input, without having to convert to HTML first
sammycage · 4 months ago
Interesting. I will give it a try. By the way, why is converting to HTML first a problem for you?
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
pac0 · 4 months ago
Does this support full flexbox styling?

What are the known issues or the unsupported css this library has?

sammycage · 4 months ago
PlutoPrint supports a large subset of CSS, including flexbox for most common layouts, but it’s not a full browser engine, so there are some limitations. You can see a more complete list of supported features here: https://github.com/plutoprint/plutobook/blob/main/FEATURES.m.... We’re also actively tracking bugs and improvements on the GitHub repo: https://github.com/plutoprint/plutoprint/issues, and contributions or test cases are always appreciated to help expand coverage.
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
leetrout · 4 months ago
What OS did you test on? It completely crashed my python process on mac
sammycage · 4 months ago
Thanks for the feedback. We’ve tested PlutoPrint on multiple platforms, including Windows and Linux, and it generally works well there. Mac-specific issues like crashes or empty outputs are definitely on our radar, and we’re investigating potential causes such as font handling, reverse mtime warnings, or system library differences. We’re also tracking bugs and improvements on the GitHub repo: https://github.com/plutoprint/plutoprint/issues. Contributions, bug reports, and additional test results from different environments are very helpful and appreciated as we continue to improve stability across all platforms.
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
socalgal2 · 4 months ago
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 discount this tool. I'm only pointing out an alternative that might be useful

sammycage · 4 months ago
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 without the overhead of a full browser.
sammycage commented on Show HN: PlutoPrint – Generate PDFs and PNGs from HTML with Python   github.com/plutoprint/plu... · Posted by u/sammycage
eterps · 4 months ago
How does it differ from https://weasyprint.org ?
sammycage · 4 months ago
WeasyPrint is great, but PlutoPrint takes a different angle: the engine is all C++, so it’s faster and lighter on memory. It can render directly to PNG as well as PDF, and has stronger SVG support.

u/sammycage

KarmaCake day87June 19, 2025
About
https://github.com/sammycage
View Original