Skip to main content

Apps Script and PDF.co integration

Please contact us to find out more: Setup Google Apps Script & PDF.co

Merge Google Drive PDF Files

Sample Code

We can break PDF.co API integration into three steps.
  • Prepare Payload
  • Prepare Request Options.
  • Invoke Request and consume the response
It’s worth observing the second step where we’re preparing options for request. Here, Request Options contain API Key in the header as well payload attribute containing JSON string. The full source code is as below.
If we quickly analyze the above source code, we’re doing the following.
  • Adding necessary references such as “Drive”, as well declaring constant for PDF.co API Key. We’re also getting references for the input Google Drive folder which contains input files.
  • In the Next Step, we’re iterating through all PDF files from a folder and uploading them to the PDF.co cloud. After the file is uploaded to PDF.co, we’re preparing an array of PDF.co cloud URLs.
  • Then we’re performing a merge using PDF.co URLs and saving result files to the output folder.