简体   繁体   中英

r pdftools: Combine multiple pages into a single page

The pdf_combine function from package can be used to combine different pdf documents.

pdftools::pdf_combine(
          input    = list(
                            "Page1.pdf"
                          , "Page2.pdf"
                          , "Page3.pdf"
                          , "Page4.pdf"
                          )
        , output   = "Pages1234.pdf"
        , password = ""
        )

Wondering if there is a way to combine these four pages into a single page something like Print multiple pages per sheet .

You can do this with the magick package...

library(magick)
files <- list.files(pattern = "\\.pdf")          #get pdf filenames
pdfs <- Reduce(c, lapply(files, image_read_pdf)) #read in and combine
montage <- image_montage(pdfs, tile = '2x2', geometry = "x1200") #create pages of 4
image_write(montage, format = "pdf", "pages1234.pdf") #save as single pdf

This works with any number of pdfs, outputting them in pages four to a page. You might want to play with the settings to get the margins, dimensions or quality to your liking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM