Saving to PDF defaults to letter paper size / adds vertical white space
billelev opened this issue · comments
When I try to save a plotly plot as a PDF the page defaults to letter size. Is there a way to specifically control the PDF size e.g. 10 x 5 inches? There is no extra white space when saving as a PNG, and I can set the pixel size exactly.
e.g.
library(plotly)
library(htmlwidgets)
library(webshot2)
fig <- plot_ly(economics, x = ~pop, type = 'histogram')
htmlwidgets::saveWidget(fig, file="temp.html")
width <- 10 * 100
height <- 5 * 100
webshot2::webshot("temp.html", "temp.pdf", vwidth = width, vheight = height)
webshot2::webshot("temp.html", "temp.png", vwidth = width, vheight = height)
webshot2::webshot
calls a function from the chromote
package to create the PDF. That function accepts arguments to change the paper size:
but the defaults are used:
Line 292 in 37a4751
So I think the answer is that you can't do that with webshot2::webshot
.
It does seem to be that way, thank you. I think the best option to get a PDF is to create a PNG and then convert to PDF.
@ant-durrant I agree webshot does, however it adds a lot of white space. To get around this I can tweak the zoom argument, but the zoom value I need varies from machine to machine. e.g. see this and this question on Stack Overflow. I have not found a consistent way to create a trimmed PDF consistently on any machine using either webshot or webshot2.