Pagedown: Multiple landscape pages

Created on 1 Nov 2019  路  7Comments  路  Source: rstudio/pagedown

Hi,

I'm wondering if it would be possible to create a multiple page report that is in landscape? For context, I'm trying to create a report that's visual-heavy (roughly 6 ggplots in a grid) for multiple companies in a report (so one page with the plots per company)

Thanks in advance.

Most helpful comment

@fmmattioni You may also consider using command-line tools to edit PDF, such as qpdf (https://github.com/qpdf/qpdf/issues/132#issuecomment-322018426), which you can call via system2() to automatically rotate a page after you pagedown::chrome_print().

All 7 comments

Hi,

Yes, it is possible to have a landscape report.
We haven't yet implemented helpers to change paper size and page orientation (but I have some ideas on this subject).

For now, here is a minimal example. First, here is an example of a CSS file for a landscape A4 paper:

@media print {
  /* paper size and orientation */
  @page {
    size: A4 landscape;
  }

  /* page break */
  .level1 {
    break-before: page;
  }
}

/* screen viewer (optional) */
:root {
  --background: whitesmoke;
  --color-paper: white;
  --color-mbox: rgba(0, 0, 0, 0.2);
  --screen-pages-spacing: 5mm;
}

@media screen {
  body {
    background-color: var(--background);
    margin: var(--screen-pages-spacing) auto 0 auto;
  }
  .pagedjs_pages {
    display: flex;
    max-width: var(--pagedjs-width);
    flex: 0;
    flex-wrap: wrap;
    margin: 0 auto;
  }
  .pagedjs_page {
    background-color: var(--color-paper);
    box-shadow: 0 0 0 1px var(--color-mbox);
    flex-shrink: 0;
    flex-grow: 0;
    margin: auto auto var(--screen-pages-spacing) auto;
  }
}

Save this file to landscape.css. You can use it in the YAML header of your R Markdown like this:

title: "Landscape mode"
date: "`r Sys.Date()`"
output:
  pagedown::html_paged:
    self_contained: false
    css: 
      - landscape.css

The Paged.js documentation provides more details on page size and orientation here.

Thanks @RLesur , will take a look

Is it possible to print only one page as landscape using this approach? I mean, my document is in portrait mode, but for a given page I would like to place it as landscape. I have tried different css commands, and although they rotate the content, the page doesn't go into landscape mode.

@fmmattioni Unfortunately, Chrome doesn't support this feature.

Thanks, @RLesur! I guess the way to go is to manually rotate the page after printing then 馃槂

@fmmattioni You may also consider using command-line tools to edit PDF, such as qpdf (https://github.com/qpdf/qpdf/issues/132#issuecomment-322018426), which you can call via system2() to automatically rotate a page after you pagedown::chrome_print().

@yihui this is a great approach! thanks for the tip!!

Was this page helpful?
0 / 5 - 0 ratings