Search

Merge the PDF files



The Merging PDF task becomes very popular across the globe for its common uses in business, education, e-learning, and beyond.


PDF merging is necessary when we have multiple PDF documents and we really need to make them into one. These separate PDF files could possibly be data analysis reports, architects’ drawings, scanned law papers, chapters of e-books, etc.


In this blog we will cover how the PDFFiddler cloud platform can help you this requirement. we will start with a simple merge requirement and check how it works for even for extremely complex scenarios also.


To know more about PDFFiddler please refer our earlier blog BASIC TUTORIAL PDFFIDDLER


Problem statement

We have N number of pdf which we want to combine into single pdf using PDFFiddler Playground



For this example, I uploaded two PDF file which I want to combine into single PDF

one-line

  • Write/Copy Paste this simple one-line script in the script section.

//merge pdf
output(merge($input))

Let try to understand the above script


$input - is a predefined keyword which represents the list of input file (list of input files which we uploaded).


merge - Predefined function which can take an array of pdf file and return single merge pdf


output - this is the final step where we want to output the merged PDF to end-user

  • Click on Run Button, on Top Right of the Page


  • Voila! Download output PDF, Single pdf as output which contains all the page of input pdfs



So far, our use case is a simple one, which can be achieved through a one-line script but as we all know business use cases are not always such straight forward. Let see how PDFFiddler work for a different kind of problem statement


  • if we want to add the blank page between merge document

docs= loadAll($input)
docs.each{ //Iterate thru all document 
    //add the blank page at last
    doc -> doc.addPages(doc.getPageCount()+1) 
}
output(merge(docs)) //merge and output doument

  • if document name contain particular keywords then only merge it

//merge pdf
docs= loadAll($input)
filtereddocs = docs.findAll{ //Iterate the document list
 //filter the document based on name
    doc -> doc.originalFilename.contains("invoice") 
}

output(merge(filtereddocs))


Let's stop this blog here. Please read another blog Advance grouping and merging to know how PDFFiddler works on a more complex problem.

PDFFiddler is the leading technology platform for generating and manipulating files in the Portable Document Format (PDF). Its mission is to develop an open marketplace for PDF related products and services.

  • White LinkedIn Icon
  • White Facebook Icon
  • White Twitter Icon
  • White YouTube Icon

© 2020 by PDFFiddler