'Xaringan: Export slides to PDF while preserving formatting
I have a Xaringan slide that looks like this:
---
title: "Xaringan test"
output:
xaringan::moon_reader:
self_contained: false
chakra: 'assets/remark-latest.min.js'
css: 'assets/presentation.css'
---
### This is a heading
This is some text and numbers 01235.
`Here is some inline code`.
```
block code
```
```{r}
cat("Some R code")
```
$e^{i\pi} + 1 = 0$
The rendered HTML looks like below. Custom font, CSS styles and mathjax all render well. This is how it is intended to look.
Exporting to PDF using Pagedown.
pagedown::chrome_print("test.html",output="test.pdf")
The custom font and css styles are preserved. The default code font has changed and the mathjax expression is not displayed. Apart from the missing mathjax, it is doing a pretty good job.
Exporting to PDF using webshot.
webshot("test.html","test.pdf")
Custom font and css styles are not preserved. The default code font and mathjax is preserved.
Anyone got any tips on how to preserve fonts, CSS style and mathjax while exporting to PDF through function?
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
webshot_0.5.1
pagedown_0.1
xaringan_0.8
Solution 1:[1]
EDIT: We've renamed the package to "renderthis" to be more general and to support other presentation types, such as Quarto presentations: https://github.com/jhelvy/renderthis
Instead of build_*(), the function names all start with to_*(), e.g.
renderthis::to_pdf("slides.Rmd")
I've been building 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. It should render to PDFs well.
https://github.com/jhelvy/xaringanBuilder
Install the package
# install.packages("remotes")
remotes::install_github("jhelvy/xaringanBuilder")
library(xaringanBuilder)
Build a pdf file from a Rmd or html file:
build_pdf("slides.Rmd")
build_pdf("slides.html")
Include "Complex" or partial slides:
“Complex” slides are slides that contain
panelsets or
other html widgets / advanced features that might not render well as a
pdf. To render these, set complex_slides = TRUE. If you want to build a
new slide for each increment on incremental
slides, set
partial_slides = TRUE.
build_pdf("slides.Rmd", complex_slides = TRUE, partial_slides = TRUE)
build_pdf("slides.html", complex_slides = TRUE, partial_slides = TRUE)
Solution 2:[2]
I tried this code Which i modified from yours.
procedure TForm1.Button1Click(Sender: TObject);
var
png: Graphics.TPortableNetworkGraphic;
begin
png := Graphics.TPortableNetworkGraphic.Create;
png.SetSize(100, 100);
png.Canvas.TextOut(10, 10, 'Hi artem!');
png.SaveToFile('tst.png');
end;
And I got this image saved.
I think nothing wrong with your code in regards to PNG image. I think it may be cause by other thing. Maybe DataModuleRequest not allow to have any graphics or UI-load processing or something. Not sure.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | GeneCode |




