2

I have created a large R Markdown document with many child docs using RStudio to produce output in both HTML and PDF.

I added this simple line to the YAML parameters of the document and it does exactly what I need. The entire doc is rendered and saved as both html and pdf output. Formatting of complex tables is preserved nicely.

knit: pagedown::chrome_print

BUT - the pdf is oversized. It simply needs to be scaled to 0.8 to be really useable. chrome_print documentation says that scale can be adjusted within the chrome_print command. I've tried this:

knit: pagedown::chrome_print(scale = 0.8)

which produces an Execution Halted error. I have tested other ways to pass parameters through the render to chrome_print, but none work.

The question is simple: Is there a way to pass parameters into the knit: pagedown::chrome_print operation?

GGAnderson
  • 1,993
  • 1
  • 14
  • 25
  • It's unclear what you're asking exactly. The scale parameter is how screenshots are taken by chrome running headless. What exactly are you trying to change? An example would help – camille Feb 10 '22 at 02:00
  • I have rewritten the question. Hope this is more clear. – GGAnderson Feb 10 '22 at 21:01

1 Answers1

3

After much experimentation, I find there is currently no way to adjust any pdf options from within R markdown YAML using knit: pagedown::chrome_print.

The workaround I've found is to use the code chunk below to render the Rmarkdown. It saves to both html and pdf formats and allows the user to assign filenames. Note that scaling does not adjust pagination nicely without CSS reset as shown. This works great, and allows full use of rmarkdown parameters and all chrome_print options.

  fname = "OutputFilename"
  pagedown::chrome_print(
    rmarkdown::render(
      input = "input.Rmd", 
      output_file = paste0(fname, ".html"),
    output = paste0(fname, ".pdf"),
    options = list(scale = 0.7, preferCSSPageSize = FALSE))
GGAnderson
  • 1,993
  • 1
  • 14
  • 25
  • I am using the Posterdown package with `chrome_print()`. I am trying to generate A0-size document. Seeing your answer, it seems that I need to use `paperWidth` and `paperHeight` in options, which is now called output_options. Is that right? – jazzurro Apr 21 '23 at 16:55