4 ms·
I am working on a HTML-to-PDF converter written from scratch in pure Go. I got tired of using headless browsers for various reasons and decided to give it a try
by radva42 7mo ago
I am working on a HTML-to-PDF converter written from scratch in pure Go. I got tired of using headless browsers for various reasons and decided to give it a try and implement something that I can use internally. However the results have far exceed my expectations and I've decided to open source everything. It's around 10x to 15x faster than wkhtmltopdf, which is by far the fastest headless browser converter. It's 80x-100x faster than a pagedjs. It's even 2x faster than PrinceXML, which is pretty much the most mature and reliable HTML-to-PDF converter on the market. It also produces the smallest PDF size.
I started small as a toy project, but gradually implemented full support for proper block context, flexbox layout, CSS variables, tables, etc. to the point where I have almost full support of all major CSS features (even math functions like calc(), min(), max()).
I'm cleaning up the code right now and will upload it later today or maybe tomorrow here: https://github.com/PureGoPDF https://github.com/PureGoPDF
- audessuscest 7mo ago> PureGoPDF doesn't have any public repositories yet.
- zufallsheld 7mo ago> I'm cleaning up the code right now and will upload it later today or maybe tomorrow here
- thom 7mo agoDo you intend to one day support all the paged media bits in pagedjs? I assume it works with their polyfill but it’d be great to have a built in more performant option.
- radva42 7mo agoCan you give an example? I'm not that familiar with pagedjs, just pulled it for the benchmark. My library has support for @page rules, but that's actually pretty basic. I needed more advanced headers/footers and added support for in-html headers/footers like this: In your <body> you cna define headers/footers by wrapping content in a <section> tag. For example: <body> <section> <header>... any HTML here, full CSS support</header> <div> Some normal flow content</div> <footer>Your footer HTML</footer> </section> </body> This structure is purely optional, but it's a really convinient way of designing pages with different styles in the same document. An HTML file can have any number of these sections meaning you can generate a PDF with different headers/footers. Some other bits: It has support for 100% height that match the entire page, it can handle forced page breaks inside flexbox containers (Chrome doesn't even try ... just ignores it) and also follows page-break: avoid correctly - so it doesn't randomly split table rows for example.
- thom 7mo agoThings like string-set and string (repeating section headers on each page), counter and target-counter (embedding page number references) etc. Prince and pagedjs support all the CSS3 paged media bits I've found myself needing, just wondering if that was on the roadmap.
- radva42 7mo agoI see. Yes, those are on the roadmap.