# PDF Generation - Google Scripts help

**URL:** <https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145>\
**Category:** Ask for Help\
**Created:** [February 2, 2021, 10:52pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145 "2021-02-02T22:52:48Z")\
**Posts on this page:** 17\
**Page:** 4

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 26, 2021, 8:41am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/61 "2021-02-26T08:41:10Z")

</div>

haha, don’t sweat. I’m a Certified Expert when it comes to putting my foot in my mouth, so you’ve got a ways to go yet 🤣

---

<div class="post-metadata">

**Author:** ![Pratik\_Shah](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pratik_shah/32/12416_2.png) [@Pratik\_Shah](https://community.glideapps.com/u/Pratik_Shah)\
**Post date:** [February 27, 2021, 12:23pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/62 "2021-02-27T12:23:53Z")

</div>

Thank you for this.  
Actually I was asking if _Document Studio_ will work upon Glide Form submission.

---

<div class="post-metadata">

**Author:** ![ehdubya](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ehdubya/32/24087_2.png) [@ehdubya](https://community.glideapps.com/u/ehdubya)\
**Post date:** [February 27, 2021, 1:52pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/63 "2021-02-27T13:52:10Z")

</div>

Does for us. Document Studio just takes whatever column/data from your Google sheet that you need formatted and modifies it into PDF. Glide allows us to deposit the data, Document Studio allows us to create PDF’s out of the deposited data.

---

<div class="post-metadata">

**Author:** ![Pratik\_Shah](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pratik_shah/32/12416_2.png) [@Pratik\_Shah](https://community.glideapps.com/u/Pratik_Shah)\
**Post date:** [February 27, 2021, 2:47pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/64 "2021-02-27T14:47:14Z")

</div>

Thank you for the response. That is good to know.  
Does Glide Form submission triggers Document Studio automatically or you will have to do it manually in GSheet?  
My requirement is, I want Document Studio to start its work as soon as Glide Form submission is done. As far as I know, it is not possible except for Time Trigger of 1 hour or 30 min?

Can you help me with this?

---

<div class="post-metadata">

**Author:** ![ehdubya](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ehdubya/32/24087_2.png) [@ehdubya](https://community.glideapps.com/u/ehdubya)\
**Post date:** [February 27, 2021, 4:01pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/65 "2021-02-27T16:01:36Z")

</div>

Yeah no problem!

To be honest, we haven’t tried it for immediate action-based triggers yet such as your use case. We use it to send out monthly reporting and invoices to clients, so I’m not sure I’d be any help (sorry!).

I know they have some extensive videos on how to use the add-ons, have you tried watching those?

---

<div class="post-metadata">

**Author:** ![Pratik\_Shah](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pratik_shah/32/12416_2.png) [@Pratik\_Shah](https://community.glideapps.com/u/Pratik_Shah)\
**Post date:** [February 28, 2021, 4:58am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/66 "2021-02-28T04:58:10Z")

</div>

I am regular user of Autocrat (since last 3-4 years) but I guess, all such add-on either has time trigger or Gform submit trigger. Additionally time trigger has a time interval of minimum 1 hour or something which does not fulfill y requirements.

---

<div class="post-metadata">

**Author:** ![Purvang\_Joshi](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/purvang_joshi/32/12645_2.png) [@Purvang\_Joshi](https://community.glideapps.com/u/Purvang_Joshi)\
**Post date:** [March 26, 2021, 8:45pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/67 "2021-03-26T20:45:02Z")

</div>

This thread helped me to achieve this. Thanks to all contributors.  
This solution is without interfering with google sheets. Also, it’ll trigger by clicking a button(webhook action)

> [@Document Merge using Google Apps Script, Webhook Action & Google Docs](https://community.glideapps.com/t/document-merge-using-google-apps-script-webhook-action-google-docs/24782):
>
> Hello, Gliders, Many of you have use-cases like, → Sending certificates to your students → Sending Auto-Generated Invoices, Quotes & Many more → creating ID cards for the events → Mail merge custom PDFs Here I’ll show you how to implement it. Demo: [https://milky-produce-8069.glideapp.io/](https://milky-produce-8069.glideapp.io/) [It’s in Personal Plan, Only 80 Webhook Actions Left] Whenever the user fills and submits a button, it’ll trigger the script and send a pdf attached mail to the receiver. The flow of the System Gli…

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [August 27, 2021, 7:13am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/68 "2021-08-27T07:13:48Z")

</div>

Hi,  
I opened a new topic and was referred here.  
I am looking for a solution to export data from GS to a printable PDF template.  
Some of the data contains URL images (Quickchart.il) and HTML+CSS Tables stored as template columns.  
I know I will have to write the template scripts to a new row to capture the data.  
I know that Document Studio give a solution for mapping columns in a word template but not sure it supports HTML or URLS.  
Any Ideas?

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [August 27, 2021, 12:20pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/69 "2021-08-27T12:20:45Z")

</div>

Is all of the data you want in the PDF in GS or is some of it still in Glide?

---

<div class="post-metadata">

**Author:** ![Lin\_Altshuler](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/lin_altshuler/32/32591_2.png) [@Lin\_Altshuler](https://community.glideapps.com/u/Lin_Altshuler)\
**Post date:** [August 28, 2021, 5:02am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/70 "2021-08-28T05:02:24Z")

</div>

some is in Glide but that’s not a problem, I guess I will “add row” to a new sheet that will write the data to GS before creating the PDF

---

<div class="post-metadata">

**Author:** ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)\
**Post date:** [January 7, 2022, 3:23am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/71 "2022-01-07T03:23:17Z")

</div>

I jump into this thread just because i am finding the way to get the file **link** using the Folder name and file name in Google Drive and @Luther recommend this thread.

I understand the script doing:

1. Get File Name to be named
2. Generate PDF
3. Send the PDF File as an attachment

That’s all i currently using.

But another crucial part is how can i get that File Link to placed on google sheet so people can straightway open in Glideapps ?

I mean like which part of the script had return this part:

> [@Uzo](#):
>
> ```auto
> function emailSpreadsheetAsPDF() {
> DocumentApp.getActiveDocument();
> DriveApp.getFiles();
> 
> // This is the link to my spreadsheet with the Form responses and the Invoice Template sheets
> // Add the link to your spreadsheet here 
> // or you can just replace the text in the link between "d/" and "/edit"
> // In my case is the text: 17I8-QDce0Nug7amrZeYTB3IYbGCGxvUj-XMt8uUUyvI
> const ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/17I8-QDce0Nug7amrZeYTB3IYbGCGxvUj-XMt8uUUyvI/edit");
> 
> // We are going to get the email address from the cell "B7" from the "Invoice" sheet
> // Change the reference of the cell or the name of the sheet if it is different
> const value = ss.getSheetByName("Invoice").getRange("B7").getValue();
> const email = value.toString();
> 
> // Subject of the email message
> const subject = 'Your Invoice';
> 
> // Email Text. You can add HTML code here - see ctrlq.org/html-mail
> const body = "Sent via Generate Invoice from Google Form and print/email it";
> 
> // Again, the URL to your spreadsheet but now with "/export" at the end
> // Change it to the link of your spreadsheet, but leave the "/export"
> const url = 'https://docs.google.com/spreadsheets/d/17I8-QDce0Nug7amrZeYTB3IYbGCGxvUj-XMt8uUUyvI/export?';
> 
> const exportOptions =
> 'exportFormat=pdf&format=pdf' + // export as pdf
> '&size=letter' + // paper size letter / You can use A4 or legal
> '&portrait=true' + // orientation portal, use false for landscape
> '&fitw=false' + // fit to page width false, to get the actual size
> '&sheetnames=false&printtitle=false' + // hide optional headers and footers
> '&pagenumbers=false&gridlines=false' + // hide page numbers and gridlines
> '&fzr=false' + // do not repeat row headers (frozen rows) on each page
> '&gid=1030891993'; // the sheet's Id. Change it to your sheet ID.
> // You can find the sheet ID in the link bar. 
> // Select the sheet that you want to print and check the link,
> // the gid number of the sheet is on the end of your link.
>   
> var params = {method:"GET",headers:{"authorization":"Bearer "+ ScriptApp.getOAuthToken()}};
>   
> // Generate the PDF file
> var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
>   
> // Send the PDF file as an attachement 
> GmailApp.sendEmail(email, subject, body, {
> htmlBody: body,
> attachments: [{
> fileName: "Invoice" + ".pdf",
> content: response.getBytes(),
> mimeType: "application/pdf"
> }]
> });
> 
> // Save the PDF to Drive. The name of the PDF is going to be the name of the Company (cell B5)
> const nameFile = ss.getSheetByName("Invoice").getRange("B5").getValue().toString() +".pdf"
> DriveApp.createFile(response.setName(nameFile));
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [January 7, 2022, 6:30am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/72 "2022-01-07T06:30:07Z")

</div>

> [@biha](#):
>
> I mean like which part of the script had return this part:
> 
> > [@Darren\_Murphy](#):
> >
> > returning a URL link to the created PDF, which is written back to the sheet

`var url = pdf.getUrl();`

---

<div class="post-metadata">

**Author:** ![biha](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/biha/32/84110_2.png) [@biha](https://community.glideapps.com/u/biha)\
**Post date:** [January 7, 2022, 6:41am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/73 "2022-01-07T06:41:57Z")

</div>

The @Uzo 's script one?

No var url = pdf.getUrl();

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 7, 2022, 9:50am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/74 "2022-01-07T09:50:50Z")

</div>

let me know if any questions… sorry for the late response… still hungover after the new year party LOL

```auto
// (c) StructureArt DIGITAL

function savePdf() {
 
  var sourceSpreadsheet = SpreadsheetApp.getActive();
  
  var sheets = sourceSpreadsheet.getSheets();
  var sheetName = sourceSpreadsheet.getActiveSheet().getName();
  var sourceSheet = sourceSpreadsheet.getSheetByName(sheetName);
  
  var pdfName = "PDF 1"; //replace with generated unique name

 
   var folder = DriveApp.getFolderById("FOLDER ID"); //replace with your public folder ID
 
  
  // Copy spreadsheet.
  
  var destSpreadsheet = SpreadsheetApp.open(DriveApp.getFileById(sourceSpreadsheet.getId()).makeCopy("tmp_convert_to_pdf", folder))

  // Delete redundant sheets.
  
  var sheets = destSpreadsheet.getSheets();
  for (i = 0; i < sheets.length; i++) {
    if (sheets[i].getSheetName() != sheetName){
      destSpreadsheet.deleteSheet(sheets[i]);
    }
  }
  
  var destSheet = destSpreadsheet.getSheets()[0];

  // Repace cell values with text (to avoid broken references).
  
  var sourceRange = sourceSheet.getRange(1,1,sourceSheet.getMaxRows(),sourceSheet.getMaxColumns());
  var sourcevalues = sourceRange.getValues();
  var destRange = destSheet.getRange(1, 1, destSheet.getMaxRows(), destSheet.getMaxColumns());
  destRange.setValues(sourcevalues);

  // Save to pdf.
  
  var theBlob = destSpreadsheet.getBlob().getAs('application/pdf').setName(pdfName);
  var newFile = folder.createFile(theBlob);

  // Delete the temporary sheet.
  
  DriveApp.getFileById(destSpreadsheet.getId()).setTrashed(true);
  
// Create file URL

   var filename = encodeURI(pdfName);
   var files = DriveApp.getFilesByName(pdfName);
   while (files.hasNext()) {
      var file = files.next();
      if (file) {
         var fileUrl = file.getUrl();
         
      };
   };

  Logger.log(fileUrl);
}

```

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 7, 2022, 10:16am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/75 "2022-01-07T10:16:56Z")

</div>

> **[Code BOOK - Desktop](https://code-book-desktop.glideapp.io/dl/ewAiAHQAIgA6ADIALAAiAHMAIgA6ACIAYwBsAGEAcwBzAC0AUwBjAHIAaQBwAHQAcwAiACwAIgByACIAOgAiAFcAOQB0AE8ARAA5AHUAdgBTAGcAUwA1AHMAYwBnAHAASQBlAFEATgBpAFEAIgAsACIAbgAiADoAIgBTAGMAcgBpAHAAdAAiAH0A/full)**
>
> share cool CSS, scripts and links

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [January 10, 2022, 5:50pm UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/77 "2022-01-10T17:50:35Z")

</div>

@biha simply set value…

sourceSheet.getRange(“A2”).setValue(fileUrl) // change A2 to your cell

---

<div class="post-metadata">

**Author:** ![Kyle\_Brabec](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/kyle_brabec/32/87373_2.png) [@Kyle\_Brabec](https://community.glideapps.com/u/Kyle_Brabec)\
**Post date:** [May 3, 2025, 7:29am UTC](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145/78 "2025-05-03T07:29:18Z")

</div>

Stuck on step 3 where I need a GCP project number. Does this cost extra because I need to make a google cloud account? I got it working with a google sheet earlier, but I’d like to use this more direct approach with only a google doc. I have yet to connect to glide.

[Previous page](https://community.glideapps.com/t/pdf-generation-google-scripts-help/22145.md?page=3)
