Combining (concatenating) PDF Blobs in Drive

644 views
Skip to first unread message

Clark Lind

unread,
May 9, 2020, 10:19:06 PM5/9/20
to Google Apps Script Community
Hi all-

Has anyone had any success combining 2 or more pdf files residing in drive with GAS? I am restricted to using apps script (or JS libraries that can be pasted in GAS as GS files). I cannot use any Drive add-ons, Chrome Extensions, or outside APIs.

Anyone have any ideas? I've tried to get jsPDF.js (as a local GS file) and Concatenate.js (as a GS file) to work, but after 12 hours beating my head against the wall, I'm finally giving up and asking for help.

It seems like it should be very easy, but I'm stumped. 

Thanks!  

Martin Hawksey

unread,
May 11, 2020, 2:03:33 PM5/11/20
to google-apps-sc...@googlegroups.com
Hi Clark,

Does it have to be server side? As in could you use client side in a modal dialog or sidebar?

Martin

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a683fa89-6dd6-4fd7-92bc-82ca8d8f8944%40googlegroups.com.


--
Martin Hawksey

Latest tweet (see how):

A bulk #GSuite email/mail merge with Gmail and Google Sheets solution evolution ... (preview of an update to the #GSuiteDevs Solution Gallery example I had published last year https://t.co/6viMWEHuDu #GoogleAppsScript pic.twitter.com/F2urK8LhFU

— Martin Hawksey #altc (@mhawksey) April 24, 2020

Clark Lind

unread,
May 11, 2020, 2:25:00 PM5/11/20
to google-apps-sc...@googlegroups.com
Hi Martin! 
It could be done in a modal. I've tried getting jsPDF and pdf-lib to work, and actually made a little progress using Bruce's code regarding ArrayBuffers. Pdf-lib uses arraybuffers, but haven't gotten further. Pdf-lib seems like an easy approach. Not afraid to try, but way above my skill level (for now lol)

Clark

You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/mzdbKLTMV0s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAEZbQn-vgpr24FMr2zWWtXQYKU15cfi%2B0i3hb8kE2iVDp0vikA%40mail.gmail.com.

Martin Hawksey

unread,
May 11, 2020, 2:46:10 PM5/11/20
to google-apps-sc...@googlegroups.com
Hi Clark,

Not tried myself but this answer on SO using PDF.js looks promising, and if you don't want to include PDF.js there are CDN versions you can use

For the pdf files you should be able to create docs from base64 encoded data.

Martin

 

Clark Lind

unread,
May 11, 2020, 6:06:43 PM5/11/20
to google-apps-sc...@googlegroups.com
Thanks Martin, 
The Base64 approach looks promising. I'll give that a go. What I am really trying to do, is a kinda mail-merge using sheets date to fill a pdf file that has a digital signature object embedded. Then email the pdf out for digital signature and return it via form (or other means). I can create the pdfs no problem, but then have to manually edit each to add the signature object. Now, if there was a javascript digital signature library or object I could use, then all this becomes moot. 

Martin Hawksey

unread,
May 13, 2020, 4:45:49 PM5/13/20
to google-apps-sc...@googlegroups.com
it looks like PDF.js has an open feature request and even displaying digital signatures requires a code tweak https://github.com/mozilla/pdf.js/issues/1076

All I can say is rather you than me - from the little I know verified digital signatures it ain't straight forward. Personally I would be making the case for integrating into a document signing service like DocuSign https://developers.docusign.com/ ... if this isn't possible really interested to hear how you solve this ;) 

Clark Lind

unread,
May 14, 2020, 11:03:30 AM5/14/20
to google-apps-sc...@googlegroups.com
Thanks Martin. I was able to get pdf-lib to work in a "good enough" way. Once I got my template all set up (including digital signature block), I was able to upload to drive, grab it as a blob and use base64 encoding/decoding, pass it to the frontend html to be processed by pdf-lib, write Names, date, etc., and then download to the local machine. Next step is to send it back from the frontend to Drive to save. So far, so good. 

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.


--
Martin Hawksey

Latest tweet (see how):

A bulk #GSuite email/mail merge with Gmail and Google Sheets solution evolution ... (preview of an update to the #GSuiteDevs Solution Gallery example I had published last year https://t.co/6viMWEHuDu #GoogleAppsScript pic.twitter.com/F2urK8LhFU

— Martin Hawksey #altc (@mhawksey) April 24, 2020

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/mzdbKLTMV0s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.


--
Martin Hawksey

Latest tweet (see how):

A bulk #GSuite email/mail merge with Gmail and Google Sheets solution evolution ... (preview of an update to the #GSuiteDevs Solution Gallery example I had published last year https://t.co/6viMWEHuDu #GoogleAppsScript pic.twitter.com/F2urK8LhFU

— Martin Hawksey #altc (@mhawksey) April 24, 2020

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/mzdbKLTMV0s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.


--
Martin Hawksey

Latest tweet (see how):

A bulk #GSuite email/mail merge with Gmail and Google Sheets solution evolution ... (preview of an update to the #GSuiteDevs Solution Gallery example I had published last year https://t.co/6viMWEHuDu #GoogleAppsScript pic.twitter.com/F2urK8LhFU

— Martin Hawksey #altc (@mhawksey) April 24, 2020

--
You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/mzdbKLTMV0s/unsubscribe.

Dora Samy

unread,
Sep 10, 2023, 3:50:12 AM9/10/23
to Google Apps Script Community
Hi Clarke,
Did you had success with pdf-lib.
i am trying to load d pdf for the front end without using native preview url

cwl...@gmail.com

unread,
Sep 10, 2023, 11:30:03 PM9/10/23
to Google Apps Script Community
Unfortunately, no. Not reliably. And I looked for any script I may have created 2 years ago, and I cannot find anything now. Sorry!

Dora Samy

unread,
Sep 12, 2023, 5:26:12 AM9/12/23
to google-apps-sc...@googlegroups.com
Hi Clarke,
Actually i am trying to render fillable pdf in to the web app for user side.
Use case - to fill the form and save and upload to drive
I have some success , but when I deploy, it is being blocked by chrome and edge browser due to iframe. 
It works perfectly  in firefox
i am rendering pdf via base64
image.png


To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a6dcd411-07ab-40e4-ab56-e3984df11f7cn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages