Merge files in Google Drive into One PDF

1,856 views
Skip to first unread message

Tárcio Sales

unread,
Mar 24, 2019, 6:35:55 PM3/24/19
to google-apps-sc...@googlegroups.com

Hi everyone!

I would like some help in order to merge some files into One PDF file. These files are in a Google Drive folder and I use the ID file to create the Blob. This files can be pictures (JPG, BMP), PDF or DOC files.

I tried to create an array of Blob or Bytes of the file but it did not work when I try to create the PDF file.

var blob1 = Utilities.newBlob(DriveApp.getFileById("17s1_taMHlseF51_RULE9d2mDticWgW2l")).getBytes() 
var blob2 = Utilities.newBlob(DriveApp.getFileById("19s1_taMHlseF51_RULE9d2mDticWgWXX")).getBytes()
blobs.push(blob1)
blobs.push(blob2) 
var pdf = Utilities.newBlob(blobs,"application/pdf") 
DriveApp.getFoldersByName(FOLDER).next().createFile(pdf)


Could someone give some idea ? Thanks.

Tarcio 

Kanshi Tanaike

unread,
Mar 25, 2019, 4:16:09 AM3/25/19
to Google Apps Script Community
Unfortunately, a PDF data cannot be created by directly merging the blobs of PDF. So as a workaround, how about using the external API?
For example,  there is "Merge PDF API".
If this was not what you want, I apologize.

Tárcio Sales

unread,
Mar 25, 2019, 10:52:56 AM3/25/19
to Google Apps Script Community

Hi Kanshi Tanaike

Thanks for your reply. It's exactly what I was looking for. However Google Drive restricts the access to our files, it's not possible to grant access to everyone (anonymous mode) then. When I try to load the file using the URL file, it did not work. :/

I will check how I can make it work with no changes on the security policies.

If you have some ides I would appreciate them.. thanks a lot.


 Request response (HTTP status code 500)
{
    "Code": 5001,
    "Message": "Conversion failed."
}

Tárcio Sales

unread,
Mar 25, 2019, 11:21:39 AM3/25/19
to Google Apps Script Community



Hi Kanshi Tanaike
I would like to share that it works perfectly as I was looking for. Thank you so much for your help! 
I just sent a blob into the Array in accordance the format. It worked! thank you! 


formData['Files[' + i + ']'] = DriveApp.getFileById(id).getBlob();


Tarcio

Haseeb Baba

unread,
Nov 14, 2022, 12:29:47 AM11/14/22
to Google Apps Script Community
Hi Tracio can you send me the source code for that ?

Lucas Bontempo

unread,
Jan 11, 2023, 7:38:13 AM1/11/23
to Google Apps Script Community
Hi Tarcio, It would be great if you can share the source code for that. Thank you!

Koltek

unread,
Mar 11, 2023, 9:50:17 AM3/11/23
to Google Apps Script Community
Hi Tárcio... It will be grate if you share with us the code...

Tanaike

unread,
Mar 11, 2023, 7:16:56 PM3/11/23
to Google Apps Script Community
Reply all
Reply to author
Forward
0 new messages