With all the different tools and confusion going on about this topic, I am wondering if we should add a function that takes care of this.
I we can agree on one tool, its much easier for users to use this function rather than reading all the recommendations in the wiki.
I would vote for decktape which produces perfect PDF outputs (no shifts, no misalignments). I use it since xaringan exists.
There is a hosted docker version that we could use.
However, ofc the user needs to have docker installed then.
Or we could add a switch in case the user has installed decktape locally.
Additionally, the function could open the produced PDF after is has been created.
I got a function for personal use but implementing it into the package would inflict some additional work ofc.
Let me know what you think :)
I would vote for the decktape version as well. I am using the docker version in a course I am teaching with students with a non-technical background. Students are able to get it working for their purposes. I personally feel the npm version is a bit messy to maintain for them. An integrated approach would be a nice addition.
+1
I would love this feature as well!
Since xaringan's html is "not so" self-contained, I prefer a pdf from time to time.
I've just started using the decktape method which works well:
system("`npm bin`/decktape remark file.html file.pdf")
It would be great if this was built in somehow.
Side question: does anyone know how to make decktape use the print CSS class? Perhaps @pat-s @zhouyisu knows? This would let me fully replace manually opening the HTML file in Chrome and printing to pdf.
I also use decktape to circumvent the glitches that can occur when printing to pdf from the browser. I've decktape installed on the computer and use the following script to convert hmtl to pdf from the command line. Just in case anyone else could use it.
#!/bin/bash
FILES="$@"
for i in $FILES
do
echo "Processing xaringan slide deck $i ..."
filename=$(basename "$i")
extension="${filename##*.}"
filename="${filename%.*}"
decktape remark $i $filename.pdf
done
I started yesterday but it seems a bit complicated. While everything works when using the terminal, all R integrations of docker (stevedock, harbor) or simply the system2() command throw weird errors.
So I went with the simple system() command which worked fine.
Next, docker is highly OS sensitive, so configuration differs a lot between OS and even among the Linux distributions. So it might be kinda hard to catch all errors messages in the first place and provide solutions.
I think documentation is the key here. Stay tuned!
If you have a recent version of Google Chrome or Chromium installed, you may try the pagedown package:
remotes::install_github('rstudio/pagedown')
pagedown::chrome_print('any-file.html')
From my quick testing, MathJax and HTML widgets don't seem to work well.
A xaringan::decktape() function has been added thanks to @pat-s. You can use either Docker or just the decktape command directly if installed. Please test the function with remotes::install_github('yihui/xaringan'). Thanks!
hi Yihui,
thanks for this. Unfortunately for me decktape doesn't work:
> decktape('rmd-intro.html', 'o.pdf')
Loading page file:///Users/stephen/papers/talks/2018/2018-12-07-rmd/rmd-intro.html ...
Loading page finished with status: 0
Remark JS plugin activated
Error: Evaluation failed: DOMException: Failed to read the 'rules' property from 'CSSStyleSheet': Cannot access rules
at _ (__puppeteer_evaluation_script__:4:20)
Error in decktape("rmd-intro.html", "o.pdf") :
Failed to convert rmd-intro.html to PDF
This is documented https://github.com/astefanutti/decktape (2nd error) and passing the extra args from the command line works(*) for me
`npm bin`/decktape --chrome-arg=--allow-file-access-from-files file.html file.pdf
(*) I say works, but not quite. The italics text in my slides are missing -- I will come up with a minimal example for this.
@sje30 I just added the argument args which defaults to --chrome-arg=--allow-file-access-from-files in decktape(). I'm not a DeckTape or Docker expert, so @pat-s please please verify if I did it correctly. Thanks!
AFAIK the local decktape installation is not very robust across OS since it needs a working combination of JS libraries and the respective chromium version (and possibly has more complicated interactions I do not know of).
For example, on Arch I usually need the arg --no-sandbox to get it working. But this is totally OS dependent.
If the default arg added does no harm to other users (we'll see) we can keep it. But I would advise against adding more and more default args that may help other people in the future.
In general, I would recommend the docker version of decktape if people face errors with the local installation. However, last time I checked the last 5 docker versions were also broken so it is always a bit of a "guessing game".
I use the hosted docker v2.8.0 since several months without problems.
Do we have other options besides decktape? the dependencies seem to be too heavy for a simple feature like "exporting to pdf"
I wrote a simple wrapper function pagedown::chrome_print() to print arbitrary HTML pages to PDF via Chrome, but currently it doesn't work well for pages containing HTML widgets or MathJax:
remotes::install_github('rstudio/pagedown')
pagedown::chrome_print('https://slides.yihui.name/xaringan/')
Exporting to PDF sounds like a simple feature, but it can be extremely complicated. The complication comes from the fact that it is hard to know when a page is ready to be printed when the page contains JavaScript code, because JavaScript can modify the DOM, and the browser has to wait until the DOM is stable. Decktape must have used certain remark.js events to know when the page has been fully processed by remark.js.
Thanks - just trying pagedown. It mostly works:
pagedown::chrome_print('https://sje30.github.io/talks/2018/rmd-intro.html')
does pretty well, but the italics (e.g. on slide 7) and mathjax are missing from the pdf. This is on mac, viewing the pdf in preview:

happy to help test/debug. source of slides are at: https://github.com/sje30/2018-12-07-rmd
@sje30 I'm not surprised by the result. We need to wait for https://github.com/rstudio/pagedown/pull/30 to be merged for a more stable pagedown::chrome_print().
remotes::install_github(c('rstudio/pagedown', 'yihui/xaringan'))
Note that at this moment, the PDF is created asynchronously, and it may surprise you that the PDF file comes a few seconds later after chrome_print() quits. I'm still working on this issue. Other that, pagedown::chrome_print() should work reasonably well now.
Thanks; see https://github.com/yihui/xaringan/pull/193 for a minor typo though (DESCRIPTION has version "0.8." rather than presumably 0.8
Fixed now. Thanks! BTW, the issue with pagedown::chrome_print() as I mentioned above has also been fixed.
Thanks. Does it now fix the italics issue I raised? (See above). It doesn't for me when I do this:
pagedown::chrome_print('https://sje30.github.io/talks/2018/rmd-intro.html')
Did you regenerate that webpage unsing the latest xaringan release so that
it's using the updated CSS?
On Sat, 9 Feb 2019 at 6:39 am, Stephen Eglen notifications@github.com
wrote:
Thanks. Does it now fix the italics issue I raised? (See above). It
doesn't for me when I do this:pagedown::chrome_print('https://sje30.github.io/talks/2018/rmd-intro.html')
—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/yihui/xaringan/issues/168#issuecomment-461921480, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACFnTtKc2NuzOSdR4CTGx9wGy59nGKi7ks5vLdJYgaJpZM4W8K9t
.
Thanks, yes, I did an install of pagedown and xaringan. does the italics work for you? The only change I made is on my laptop, I have to add browser="google-chrome-stable" to the call to chrome_print.
sorry, I misunderstood. No, I haven't remade the .html file. Let me try that now!
It seems you have regenerated the HTML page: https://github.com/sje30/sje30.github.io/commit/e6f3764741e1a2a19b2a44ce9879abd9f8680cd5 I just tested it. The italic text and MathJax expression are no longer missing:

Thanks for testing it! Yes, I was just in the process of updating and telling you. Thanks for taking the time on this. I appreciate it.
Hello,
I was just trying this new fix and it prints well except for the plots. I get the following error message:
pagedown::chrome_print("C:/Users/aaalvarez/Documents/cox/pres_1.html")
[2019-02-12 17:49:47] [error] handle_read_frame error: asio.system:10054 (An existing connection was forcibly closed by the remote host.)
[2019-02-12 17:49:47] [info] asio async_write error: asio.system:10054 (An existing connection was forcibly closed by the remote host.)
[2019-02-12 17:49:47] [fatal] handle_write_frame error: websocketpp.transport:2 (Underlying Transport Error)
Does anyone know what this could be? I'll appreciate any comment
@MadNietzsche Please see https://github.com/rstudio/pagedown/issues/68.
Thanks for this feature-- I annotate slides in class on my ipad so the pdf conversion is very useful! I was wondering if incremental bullet points are supported in any of the pdf conversion tools? It would be awesome if incremental bullets were split across slides when converting to pdf (i.e. the way beamer handles incremental bullets).
@afranks86 It is possible, but please file a new issue or ask questions in public forums instead of replying to a closed issue. It feels stressful when an issue can never been truly closed...
FYI, I've been working on a package that builds xaringan slides to multiple output types: html, pdf, pptx, gif, and a couple options for a png of the first slide:
https://github.com/jhelvy/xaringanBuilder
Most helpful comment
FYI, I've been working on a package that builds xaringan slides to multiple output types: html, pdf, pptx, gif, and a couple options for a png of the first slide:
https://github.com/jhelvy/xaringanBuilder