MergePDFs: Merge PDF Files

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/MergePDFs.R

Description

This function combines Portable Document Format (PDF) files into a single new PDF file.

Usage

1
MergePDFs(path, pdfs, preserve.files = FALSE, open.file = FALSE)

Arguments

path

character. Path name of the folder containing the PDF files to merge.

pdfs

character. Vector of file names, if missing, all PDF files under path will be merged.

preserve.files

logical. If true, all individual PDF files are preserved after a merge is completed.

open.file

logical. If true, the merged PDF file is opened using your systems default PDF viewer.

Details

Names of the individual PDF files are used as bookmarks in the merged file. The merged file is placed one directory above the path folder.

Value

Returns the name of the merged file.

Note

Requires PDFtk Server, a cross-platform command-line tool for working with PDFs.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

See Also

RunAnalysis, system

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
  # Create a temporary directory
  dir.create(path <- file.path(tempdir(), "merge"))

  # Write three single-page PDF files to the temporary directory
  pdf(file.path(path, "f1.pdf"))
  plot(seq_len(10), main = "f1a")
  plot(sin, -pi, 2 * pi, main = "f1b")
  plot(qnorm, col = "red", main = "f1c")
  dev.off()
  pdf(file.path(path, "f2.pdf"))
  plot(table(rpois(100, 5)), type = "h", col = "yellow", main = "f2a")
  dev.off()
  pdf(file.path(path, "f3.pdf"))
  plot(x <- sort(rnorm(47)), type = "s", col = "green", main = "f3a")
  plot(x, main = "f3b")
  dev.off()

  # Merge PDF files into a single file and open it in your default viewer
  MergePDFs(path, open.file = TRUE)

  # Remove PDF files
  unlink(path, recursive = TRUE)

jfisher-usgs/Trends documentation built on May 19, 2019, 7:16 a.m.