Live data from Hacker News

Using Web Technologies to Print a Book

richardmavis.info

21–30 of 69 posts

Re: Using Web Technologies to Print a Book

#21

Last time I seriously tried wkhtmltopdf (three or four years ago, at a guess), it produced results entirely unsuitable for printing in quite a few ways: • It completely mangled the kerning, like it was ignoring the font’s kerning and then making it even worse by only placing characters to 1pt precision (at 600dpi, one dot is 0.12pt). (To clarify: I never actually measured it; this is just my rough guess as to what ma…

Puppeteer works perfectly https://medium.com/@raphaelstaebler/advanced-pdf-generation-...

Re: Using Web Technologies to Print a Book

#22
Last time I checked (maybe 2 years ago?) there wasn't a good open source html to pdf workflow. Specifically page-numbers and anything else involved with paged media is a nightmare, the CSS standards in that regard are not implemented. There is "Prince", but it isn't OSS and rather expensive.

Phantomjs (and its ilk) are based on browser engines and just don't support this. Also I would love to be able to change layout or content based on where particular elements turn up.

Re: Using Web Technologies to Print a Book

#24

Last time I checked (maybe 2 years ago?) there wasn't a good open source html to pdf workflow. Specifically page-numbers and anything else involved with paged media is a nightmare, the CSS standards in that regard are not implemented. There is "Prince", but it isn't OSS and rather expensive. Phantomjs (and its ilk) are based on browser engines and just don't support this. Also I would love to be able to change layout…

WeasyPrint supports CSS Paged Media and is open source. Yes, anything based on browser engines do not support CSS Paged Media.

Re: Using Web Technologies to Print a Book

#25

Last time I seriously tried wkhtmltopdf (three or four years ago, at a guess), it produced results entirely unsuitable for printing in quite a few ways: • It completely mangled the kerning, like it was ignoring the font’s kerning and then making it even worse by only placing characters to 1pt precision (at 600dpi, one dot is 0.12pt). (To clarify: I never actually measured it; this is just my rough guess as to what ma…

Puppeteer works perfectly https://medium.com/@raphaelstaebler/advanced-pdf-generation-...

Nope, that uses Chromium, which does not support any CSS Paged Media.

Re: Using Web Technologies to Print a Book

#26
post #24

Last time I checked (maybe 2 years ago?) there wasn't a good open source html to pdf workflow. Specifically page-numbers and anything else involved with paged media is a nightmare, the CSS standards in that regard are not implemented. There is "Prince", but it isn't OSS and rather expensive. Phantomjs (and its ilk) are based on browser engines and just don't support this. Also I would love to be able to change layout…

WeasyPrint supports CSS Paged Media and is open source. Yes, anything based on browser engines do not support CSS Paged Media.

WeasyPrint looks to have progressed a lot since last I looked at it (when there was no way I could use it at all, though I can’t remember the reason), but looks to still be quite limited. A couple of things that spring to my attention immediately: no flexbox, and no CSSOM (so that you can’t adjust the document based on layout at all unless you can do it in straight CSS). Still, in practice probably usable for what I was doing several years ago, with similar limitations to Prince (which also has no CSSOM implementation, though at least it has a JavaScript engine). But anything more advanced in the way of fine page-dependent layout, I get the impression that WeasyPrint won’t be able to do, while Prince is superb at handling such things.

Re: Using Web Technologies to Print a Book

#27
post #24

Earlier quoted context omitted.

WeasyPrint supports CSS Paged Media and is open source. Yes, anything based on browser engines do not support CSS Paged Media.

WeasyPrint looks to have progressed a lot since last I looked at it (when there was no way I could use it at all, though I can’t remember the reason), but looks to still be quite limited. A couple of things that spring to my attention immediately: no flexbox, and no CSSOM (so that you can’t adjust the document based on layout at all unless you can do it in straight CSS). Still, in practice probably usable for what I…

Yup, Prince is great. There are reasons they can get paid when WeasyPrint is free. But my parent post already knew about Prince and specifically wanted to know about an OSS one.

Re: Using Web Technologies to Print a Book

#28
Unsolicited code review:

    system("multimarkdown -s ../#{part}/story.md | sed -E 's/_([^_]+)_/\\1/g' | sed -E 's///g' | sed 's/

%/%/g' > output-#{part}.html")

IMO:

    s_

%

_%

_g
is easier to read than:

    s/

%/%/g

Any reason to keep the %-sign?

Those sed commands could probably be reduced to one invocation of sed(1) instead of three.

    system("cat #{htmls} | #{wkhtmltopdf_cmd} --footer-html footer.html - body.pdf")
No need to use cat.

Re: Using Web Technologies to Print a Book

#29
post #24

Last time I checked (maybe 2 years ago?) there wasn't a good open source html to pdf workflow. Specifically page-numbers and anything else involved with paged media is a nightmare, the CSS standards in that regard are not implemented. There is "Prince", but it isn't OSS and rather expensive. Phantomjs (and its ilk) are based on browser engines and just don't support this. Also I would love to be able to change layout…

WeasyPrint supports CSS Paged Media and is open source. Yes, anything based on browser engines do not support CSS Paged Media.

Looks interesting.

In general I think Tex/LaTex is the way to go in terms of reporting and generation of pdf. The biggest problem with Tex is that it is so different from HTML, and it gets progressively more different and difficult if you have specific layout or style requirements.

What I wish for is a replacement for LaTeX, based mostly on web standards, extensible in javascript... Unfortunately I don't have the resources to do that.

Re: Using Web Technologies to Print a Book

#30
post #24

Earlier quoted context omitted.

WeasyPrint supports CSS Paged Media and is open source. Yes, anything based on browser engines do not support CSS Paged Media.

WeasyPrint looks to have progressed a lot since last I looked at it (when there was no way I could use it at all, though I can’t remember the reason), but looks to still be quite limited. A couple of things that spring to my attention immediately: no flexbox, and no CSSOM (so that you can’t adjust the document based on layout at all unless you can do it in straight CSS). Still, in practice probably usable for what I…

One of the problem with CSSOM and similar things is the problem of iterative layout: Let's say you have a list which should be split automatically on two pages. You also want to add a table header on the second page. But now the second part of the list doesn't fit on the page anymore. So you need to split the list further, and add another header.

Basically every change to the CSS or DOM requires a reflow (or clever optimizations to avoid that).

Post reply on HN