Anyone try and use a headless browser to automatically make PDF from rmarkdown?

LaTeX is great and all, but so few people know how to custom style those templates. I work with and can hire lots of designers who can do wonders with HTML and CSS. I’m wondering if anyone has ever used a setup like invoking a print method as save to pdf in a headless browser or similar to generate PDFs from styled HTML and not via pandoc using Rmd to md to tex to pdf as a path.

1 Like

It looks like webshot is one such attempt, but PhantomJS is end of life and doesn't support a bunch of stuff that's available in current browsers. Looks like there's no timeline for using headless Chrome (and looking at the code I'm not sure how to move in that direction myself, unfortunately).

You also have this one that can work with other than phantomjs I believe.

Also there a WIP :package: for rmarkdown with paged media. That could be what you are looking for. Pretty impressive result.

I think there will be an introduction presentation soon by Romain at uRos 2018. Will post it here.when available .

In the meantime

2 Likes

Thanks Christophe for introducing weasydoc!

Jason, the facts you described were exactly the starting point for reengineering my PDF toolchain without LaTeX. I confirm that it is feasible to forget LaTeX and produce high quality PDF with HTML+CSS.

The process behind weasydoc is the following:

  • Rmd to md with knitr
  • md to html with pandoc
  • html+CSS Paged Media to pdf with dedicated tools (browsers do not support CSS Paged Media): PDF styling is done only with CSS rules.

Note: If you are looking for the 3rd step only, you can use weasydoc::make_pdf(), it takes an html file in entry.

I gathered some references about CSS Paged Media in the weasydoc README. I hope it can be helpful!

I'm polishing my slides for the uRos2018 conference next week. I'll post a link to the slideshow here.

4 Likes

Here is the link to my slides for my talk on Alternative to LaTeX for High Quality Reports https://speakerdeck.com/rlesur/alternative-to-latex-for-high-quality-reports-with-rmarkdown

3 Likes