0

I'm using Google App Scripts to manipulate some PDFs.

I have two PDFs and want to merge them into one - im trying to use Merge Multiple PDF's into one PDF

One of the PDFs is in version 1.4 and have the trailer.

The other is a PDF generated based on a gdoc and gets in version 1.5 and does not have trailer.

Code i use to generate PDF file:

var docblob =  DriveApp.getFileById("fileID").getAs('application/pdf');
docblob.setName("TEST pdf");
var file = DriveApp.createFile(docblob);
var fileId = file.getId();

Script of Merge Multiple PDF's into one PDF is not dealing right with this last file because does not have trailer.

Does anyone have a solution to generate a pdf in 1.4 version using appscripts? Or other solution to merge pdf files on appscripts?

JingleBells
  • 47
  • 1
  • 11
  • I could think of OCR conversion, but this would imply losing formatting. Would this be an issue for you? – ziganotschka Jan 09 '20 at 16:48
  • Can I ask you about the file type of `fileID` of `var docblob = DriveApp.getFileById("fileID").getAs('application/pdf')`? – Tanaike Jan 09 '20 at 22:17
  • Hi @Tanaike, its a gdoc (text document from google) – JingleBells Jan 10 '20 at 16:34
  • Thank you for replying. I could understand `fileID` of `var docblob = DriveApp.getFileById("fileID").getAs('application/pdf')` is the Google Document. In this case, can I ask you about `I have two PDFs`? From your replying, I thought that you wanted to merge 2 Google Documents as one PDF. But in your question, you have 2 PDF files which are v1.4 and v1.5. You have already had a PDF file of v1.4 and you want to merge it and the PDF file (v1.5) converted from Google Document. Is my understanding correct? If I misunderstood your situation, please modify. – Tanaike Jan 10 '20 at 23:32
  • Hi @Tanaike, Exactly: one PDF (i have in my Drive generated by other application) in version 1.4. The other PDF is generated based on a GDOC and gets generated in version 1.5. The main problem is that the pdf generated using getAs('application/pdf') is not having the trailer tag at the end so the script i found on the post i tagged is not working. – JingleBells Jan 13 '20 at 10:36
  • Thank you for replying. In your case, if to use the external API is included in your direction, how about using https://www.convertapi.com/pdf-to-merge or https://www.convertapi.com/docx-to-pdf ? If those are not the direction you want, I apologize. – Tanaike Jan 13 '20 at 23:26

1 Answers1

0

Slightly old question, but would have liked finding a reply so I'll put one for future reference.

I tried using the SO suggestion you mentioned a few days ago and could not make it work either, even if I had two 1.4 PDFs.

I asked the author to be sure: @pokycoder kindly confirmed that his code is suitable only for PDF versions <1.4 (strictly less than, i.e. not including 1.4). So neither of your files would be handled by the code even if they were of the same version.

(As a curiosity: he commented it would not be intuitive to upgrade the code because "the trailer dictionary is a compressed data stream.")

Giampaolo Ferradini
  • 529
  • 1
  • 6
  • 17