yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

html/css rendering to PDF #2329

Closed aaelony closed 4 months ago

aaelony commented 4 months ago

Is there any consideration towards functionality that outputs PDF in a manner that supports CSS/HTML look and feel in a manner that uses headless websites (that could work in a docker container) and not LaTeX? Seeking an R package that supports programmatic Rmd to PDF file format that honors CSS directives with the same look and feel that the browser would render. Any thoughts or pointers to existing packages welcome. Thank-you.

cderv commented 4 months ago

We have experimented with pagedown (https://github.com/rstudio/pagedown) which leverages Paged.js technology (https://pagedjs.org/). It allows to use HTML / CSS and JS to produce paginated HTML which then can be printed more easily.

Some users have been able to create nice template with it: https://pagedreport.rfortherestofus.com/

aaelony commented 4 months ago

Ended up using Puppeteer via it's Docker container (https://pptr.dev/guides/docker) which works well. This or something like it could be wrapped into an R package as desired.

cderv commented 4 months ago

If you are looking for just HTML printing to PDF, R ecosystem has several tooling using same tech layer than puppeteer to interact with chrome

If you want to stay in R only, they can help. But otherwise, Puppeteer is a really good option for this.