Printing and/or Saving RPubs post as pdf

436 Views Asked by At

I attempted to save or print the RPubs post as a PDF document, but I was unsuccessful. I also experimented with the provided code, but it didn't work either as required.

library(webshot)
webshot(
    url     = "https://rpubs.com/Zahidasghar/LDEP"
  , file    =  "Output1.pdf"
  , vwidth  = 992
  , vheight = 744
  )

On the other hand, it converts the entire post into a single-page document that is not suitable for printing.

Edited

Also tried wget without any success.

1

There are 1 best solutions below

0
On BEST ANSWER

The issue is caused by embedding the content of the article via iframe. When you look on the page source(s) of RPubs articles, you will find a part like:

<div id='pagebody'>
<div id='payload'>
<iframe allow='fullscreen' src='//rstudio-pubs-static.s3.amazonaws.com/1059356_eb7073491a644e91a1a854c87ad20780.html'></iframe>

where src links to original version of the article. Follow up the link and print out/convert to pdf the pages.

Using R, something like:

r <- readLines(con = "https://rpubs.com/EmilOWK/norway_math_gaps")
r <- r |> 
  subset(grepl("iframe", r))
r |>
  stringr::str_sub(start = 28, nchar(r)-11) |>
  stringr::str_replace(pattern = "src=\'", replacement = "https:")
#> [1] "https://rstudio-pubs-static.s3.amazonaws.com/1059356_eb7073491a644e91a1a854c87ad20780.html"

Created on 2023-07-01 with reprex v2.0.2