# Creating PDF

**URL:** <https://community.glideapps.com/t/creating-pdf/17417>\
**Category:** Ask for Help\
**Created:** [October 21, 2020, 6:04pm UTC](https://community.glideapps.com/t/creating-pdf/17417 "2020-10-21T18:04:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adviuz](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Adviuz](https://community.glideapps.com/u/Adviuz)\
**Post date:** [October 21, 2020, 6:04pm UTC](https://community.glideapps.com/t/creating-pdf/17417/1 "2020-10-21T18:04:04Z")

</div>

How to create PDF file. We are looking to generate Invoices for client.

---

<div class="post-metadata">

**Author:** ![abhilashabhatia](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/abhilashabhatia/32/10618_2.png) [@abhilashabhatia](https://community.glideapps.com/u/abhilashabhatia)\
**Post date:** [October 21, 2020, 6:17pm UTC](https://community.glideapps.com/t/creating-pdf/17417/2 "2020-10-21T18:17:25Z")

</div>

Try out a PDF generator service via Zapier like PDFMonkey.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [October 22, 2020, 4:00am UTC](https://community.glideapps.com/t/creating-pdf/17417/3 "2020-10-22T04:00:15Z")

</div>

+1 for PDFMonkey, but make sure you have an understanding of HTML and JSON to make a nice template. The rest is just about matching the right columns to the JSON generated from Sheets.

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 15, 2020, 11:20pm UTC](https://community.glideapps.com/t/creating-pdf/17417/4 "2020-12-15T23:20:44Z")

</div>

The goal then is to save the download link of the generated PDF in the sheet. And this is possible with an additional task.  
I’ve tried and it works fine.

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [December 15, 2020, 11:40pm UTC](https://community.glideapps.com/t/creating-pdf/17417/5 "2020-12-15T23:40:13Z")

</div>

Yes, what I did is upload them to my Drive and take the Drive link to update back to the Sheet.

---

<div class="post-metadata">

**Author:** ![Jaime](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jaime/32/72726_2.png) [@Jaime](https://community.glideapps.com/u/Jaime)\
**Post date:** [December 16, 2020, 4:13am UTC](https://community.glideapps.com/t/creating-pdf/17417/6 "2020-12-16T04:13:41Z")

</div>

Gsheets \> Integromat \> Google Docs template

---

<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:** [December 16, 2020, 4:34am UTC](https://community.glideapps.com/t/creating-pdf/17417/7 "2020-12-16T04:34:29Z")

</div>

You can skip the Integromat step with single line of App Script 😉

`var pdf = DriveApp.getFileById(FILE_ID).getBlob().getAs('application/pdf');`

---

<div class="post-metadata">

**Author:** ![Pablo\_books](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/pablo_books/32/2110_2.png) [@Pablo\_books](https://community.glideapps.com/u/Pablo_books)\
**Post date:** [December 16, 2020, 4:36am UTC](https://community.glideapps.com/t/creating-pdf/17417/8 "2020-12-16T04:36:53Z")

</div>

You and your code! 😛

---

<div class="post-metadata">

**Author:** ![Jaime](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jaime/32/72726_2.png) [@Jaime](https://community.glideapps.com/u/Jaime)\
**Post date:** [December 16, 2020, 4:47am UTC](https://community.glideapps.com/t/creating-pdf/17417/9 "2020-12-16T04:47:33Z")

</div>

Whoa, thanks!

---

<div class="post-metadata">

**Author:** ![raghav\_khandelwal](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/raghav_khandelwal/32/12492_2.png) [@raghav\_khandelwal](https://community.glideapps.com/u/raghav_khandelwal)\
**Post date:** [December 16, 2020, 6:47am UTC](https://community.glideapps.com/t/creating-pdf/17417/10 "2020-12-16T06:47:42Z")

</div>

Hey @Darren_Murphy, can you help me with entire App script for this… in case you have it handy. Thanks in advance! 🙂

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 16, 2020, 9:57am UTC](https://community.glideapps.com/t/creating-pdf/17417/11 "2020-12-16T09:57:47Z")

</div>

🤪

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 16, 2020, 10:17am UTC](https://community.glideapps.com/t/creating-pdf/17417/12 "2020-12-16T10:17:40Z")

</div>

@ThinhDinh How did you solve the problem of replacing, in the preparation of the JSON data packet, the special characters such as ’ e " (quote and double quote) with the relative escape sequences? Can this be done simply using only the data editor in your opinion?

---

<div class="post-metadata">

**Author:** ![Roldy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/roldy/32/36068_2.png) [@Roldy](https://community.glideapps.com/u/Roldy)\
**Post date:** [December 16, 2020, 10:27am UTC](https://community.glideapps.com/t/creating-pdf/17417/13 "2020-12-16T10:27:54Z")

</div>

With “simply” I mean without using split & join techinique…

---

<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:** [December 16, 2020, 11:24am UTC](https://community.glideapps.com/t/creating-pdf/17417/14 "2020-12-16T11:24:02Z")

</div>

> [@raghav\_khandelwal](#):
>
> Hey @Darren_Murphy, can you help me with entire App script for this… in case you have it handy. Thanks in advance! 🙂

I didn’t have one handy, but I tossed a a generic example together 😛

The following accepts two parameters:

1. `source_doc_id`: ID of the source document/template
2. `folder_id`: ID of the folder where the PDF will be saved

It does the following:

- Makes a temporary copy of the source document
- Adds a “random” line of text to that copy
- Creates a PDF copy
- Moves that PDF to the target folder
- Trashes the temporary file

> **Summary**
>
> ```
> function convert_doc_to_pdf(source_doc_id, folder_id) {
>    
> // Make a copy of the original document
> var doc_name = DriveApp.getFileById(source_doc_id).getName();
> var temp_file = DriveApp.getFileById(source_doc_id).makeCopy('temp');
> var temp_doc_id = temp_file.getId();
>   
> // Open the copy, add some random text, save and close it
> var temp_doc = DocumentApp.openById(temp_doc_id);
> var body = temp_doc.getBody();
> body.appendListItem('Some random text');
> temp_doc.saveAndClose();
>   
> // Create the PDF and move it to the target folder
> var blob = DriveApp.getFileById(temp_doc_id).getBlob().getAs('application/pdf');
> blob.setName(doc_name + '.pdf');
> var pdf = DriveApp.createFile(blob);
> var folder = DriveApp.getFolderById(folder_id);
> pdf.moveTo(folder);
>   
> // Trash the temp copy of the original
> temp_file.setTrashed(true);
> }
> 
> ```

Any questions, just ask 😃

---

<div class="post-metadata">

**Author:** ![raghav\_khandelwal](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/raghav_khandelwal/32/12492_2.png) [@raghav\_khandelwal](https://community.glideapps.com/u/raghav_khandelwal)\
**Post date:** [December 16, 2020, 12:01pm UTC](https://community.glideapps.com/t/creating-pdf/17417/15 "2020-12-16T12:01:42Z")

</div>

Great! Thank you so much for your help and time!  
Just 1 thing, how to to get the file id back in the Google sheets?

---

<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:** [December 16, 2020, 12:11pm UTC](https://community.glideapps.com/t/creating-pdf/17417/16 "2020-12-16T12:11:30Z")

</div>

The File ID is shown in the URL when you open a doc:

 ![Screen Shot 2020-12-16 at 8.07.33 PM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/8/6891314a2c0b46b9b650b620e74897568d64e076.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [December 16, 2020, 12:13pm UTC](https://community.glideapps.com/t/creating-pdf/17417/17 "2020-12-16T12:13:59Z")

</div>

That’s tricky. Admittedly I haven’t faced that (I think) but can you try these escape characters.

`%22 for double quote`  
`%27 for single quote`

> **[HTML URL Encoding Reference](https://www.w3schools.com/tags/ref_urlencode.ASP)**

---

<div class="post-metadata">

**Author:** ![raghav\_khandelwal](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/raghav_khandelwal/32/12492_2.png) [@raghav\_khandelwal](https://community.glideapps.com/u/raghav_khandelwal)\
**Post date:** [December 16, 2020, 12:16pm UTC](https://community.glideapps.com/t/creating-pdf/17417/18 "2020-12-16T12:16:51Z")

</div>

Sorry, I was not clear with my Question.  
What I wanted to ask is if we can get the file id of the Pdf generated in the Google sheet. So as to display the same directly in the app.

---

<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:** [December 16, 2020, 12:18pm UTC](https://community.glideapps.com/t/creating-pdf/17417/19 "2020-12-16T12:18:41Z")

</div>

oh, right…  
Referring back to that example script, you can just use `pdf.getId();`

---

<div class="post-metadata">

**Author:** ![raghav\_khandelwal](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/raghav_khandelwal/32/12492_2.png) [@raghav\_khandelwal](https://community.glideapps.com/u/raghav_khandelwal)\
**Post date:** [December 16, 2020, 12:20pm UTC](https://community.glideapps.com/t/creating-pdf/17417/20 "2020-12-16T12:20:24Z")

</div>

Cool! Thanks for your Help! 🙂

[Next page](https://community.glideapps.com/t/creating-pdf/17417.md?page=2)
