我有一个生成 PDF
的 r-scipt通过以下方式...
baseplot
制作了 100 多个图形和 ggplot
.这些图是用 pdf
生成的设备。我使用的原因 pdf
是我需要嵌入字体(在 tex 标签中使用自定义字体)。 Sweave
生成 .tex
将所有图表收集在一起。 MikTeX
生成PDF。 事实证明,生成图形所需的时间的 75-95% 是由
embed_fonts
占用的。称呼。有什么办法可以少做embed_fonts
(这似乎是 ghostscript 的包装器)调用?理想的 vatiant 是只嵌入一次调用。那可能吗?
最佳答案
也许你可以使用 cairo_pdf
应该嵌入字体的设备。cairo_pdf
似乎比 pdf
慢但比 pdf + embedFonts
快.
当然,仅在最终的 pdf 文档中嵌入字体将是更好的解决方案......
library(microbenchmark)
res_pdf <- microbenchmark({
f = tempfile(fileext = '.pdf')
pdf(f); pairs(iris); dev.off()
})
res_embed <- microbenchmark({
f = tempfile(fileext = '.pdf')
pdf(f); pairs(iris); dev.off()
embedFonts(f)
})
res_cairo <- microbenchmark({
f = tempfile(fileext = '.pdf')
cairo_pdf(f); pairs(iris); dev.off()
})
res_pdf
#> Unit: milliseconds
#> min lq mean median uq max neval
#> 16.67764 17.0388 18.05949 17.32904 18.18776 60.2542 100
res_embed
#> Unit: milliseconds
#>
#> min lq mean median uq max neval
#> 250.046 252.7647 257.4749 255.2785 259.4858 303.0072 100
res_cairo
#> Unit: milliseconds
#>
#> min lq mean median uq max neval
#> 84.25745 86.60512 88.42902 88.36698 89.5705 111.5881 100
关于R + ggplot + pdf 设备 + LaTeX : is it possible to embed fonts one time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48746184/