3

I have created a gs script to autofill certain information from G-Sheet to a G-Doc template (so to make the final G-Doc content more personalized).

I managed to write a script to create G-Doc url automatically once its autofilled. Now, I want to convert the G-Doc URL to PDF.

Please help!

See below, the first column is where the G-Doc URL is automatically created, how do I do auto-create PDF URL on the second column?

columns where the URLs sit

here is the final part of the script for creating and saving G-doc URL:

 doc.saveAndClose();
 const url = doc.getUrl();
 sheet.getRange(index +1,154).setValue(url)
Yvette Liu
  • 31
  • 1
  • Here is another post that has a similar request: https://stackoverflow.com/questions/28312992/convert-google-doc-to-pdf-using-google-script-editior The only difference is that you would use DocumentApp.openByUrl(url) instead of getting the active. – OneInAMillion Jun 01 '22 at 16:06

1 Answers1

0

You can try the following:

doc.saveAndClose();
const url = doc.getUrl();
const docID = doc.getId();
const pdfURL = url.toString().replace("/open?id=" + docID, "/document/d/" + docID + "/export?format=pdf");

And just add the last line to specify where in the sheet you want to set the pdfURL

Lorena Gomez
  • 1,946
  • 2
  • 4
  • 11