Appending a pre-existing PDF to a new created by R Markdown

I wanted to add an addendum to my post describing the final solution to this problem.

While I didn't use any of the suggested methods specifically, in the course of investigating all three methods, the specific answer to my problem became clear. Actually, it was pretty straight-forward.

In a script file, I first called and knitted the markdown document using the render() command and saved the markdown PDF output to the same directory where the second PDF was located. In this development case, that happened to be the master project directory. If you need to specify a different directory, use the here() package.

Then, I used pdftools::pdfcombine() to combine the two PDFs and save the output to a specific directory (Again, in this example, that is the master project directory).

#create and output "two_joined_pdfs" PDF

# https://www.r-bloggers.com/join-split-and-compress-pdf-files-with-pdftools/

rmarkdown::render("name_of_markdown_doc.Rmd",
                  output_file = "name_of_markdown_doc.pdf")

# merge "name_of_markdown_doc" PDF with "second_PDF" PDF

library(pdftools)
pdf_combine(c("name_of_markdown_doc.pdf", "second_PDF.pdf"), 
output = "two_joined_pdfs.pdf")

Thanks to @mara, @joels, and @Timesaver for sharing their insight and suggestions.

Linda

6 Likes