Join the same pdf to a bunch of pdfs in R

So I would like to add the same pdf cover page to all the individual pdfs in a folder, then put the combined files into a different folder.
The folder architecture looks like this:

     +-- cover.pdf
     +-- inputfolder
     |  |  
     |  +-- file01.pdf
     |  +-- file02.pdf
     |  +-- file03.pdf
     |  +-- file04.pdf
     |  +-- etc...
     +-- outputfolder
     |  |  
     |  +-- cover+file01.pdf
     |  +-- cover+file02.pdf
     |  +-- etc...

So I want the end result to be cover+inputfile# for each different file in the input folder to end up in the output folder.

I cant quite figure out how to format things for lapply or loops

    FILELIST <- list.files(path = "~/inputfolder", pattern="*.pdf", full.names = T)
    for (i in FILELIST) {
      pdf_combine(input = c("cover.pdf", i),
                      output = "i.pdf")

*Note I do NOT want to merge all of them. Theres enough examples of that Ive found already

If i iterates over all the pdf file names and you want to overwrite the original files, then simply use output = i)

As you say this overwrites the originals.
An alternative is

myroot <- getwd()
FILELIST <- list.files(path=paste(myroot,"/inputfolder",sep=""),pattern="*.pdf", full.names = F)
for (i in FILELIST) {
      pdf_combine(input = c("cover.pdf", paste(myroot,"/inputfolder/",i,sep="")),
                      output = paste(myroot,"/outputfolder/",i,sep=""))
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.