Export Google Doc URLs from a specific Google Sheet cell and convert to PDF

Viewed 57

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)
1 Answers

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

Related