# Example: PDF Generator

**URL:** <https://forum.wixstudio.com/t/example-pdf-generator/22504>\
**Category:** Show and tell\
**Tags:** tips, code\
**Created:** [August 15, 2019, 10:44am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504 "2019-08-15T10:44:00Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 15, 2019, 10:44am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/1 "2019-08-15T10:44:00Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/f/0/f0933c6fb68e660bdbab224d6a784d5634b65767.png)

**Demonstrates**

- [NPM library / Package Manager](https://support.wix.com/en/article/corvid-managing-external-code-libraries-with-the-package-manager)

- [wix-location.to()](https://www.wix.com/corvid/reference/wix-location.html#to)

**Links for this example**

- [Site View](https://www.wix.com/code-examples/pdf-generator-view)

- [Example Template](https://editor.wix.com/html/editor/web/renderer/new?siteId=39e50edb-b205-4839-98ac-8e3132678771&metaSiteId=88f167ff-6c40-4571-b1bb-c719d917f9df)

**About this example**

This example uses the [PDF Generator API](https://pdfgeneratorapi.com/) as a tool to create a PDF template that will be used by your site to create a PDF document from site data. To get started, do the following:

- From the [Wix Package Manager](https://support.wix.com/en/article/corvid-managing-external-code-libraries-with-the-package-manager) in the Editor, install the **pdf-generator-api** NPM library.

- Open a [PDF Generator API sandbox account](https://pdfgeneratorapi.com/signup) .

- Go to the **Account Settings** page of your PDF Generator API account.

- Copy the API KEY, and the API SECRET codes from the Settings page into their appropriate places in the **pdfGenerator.jsw** file of the example template.

- To create a template, go to the **Templates** page of your PDF Generator API account.

- Click on the **New Template** button.

- Select the **No Data** option.

- Select **Import** from the **File** menu.

- Import the [**pdf-example-template.json**](https://wixmp-39ab0c0354ff50648f4c4e4f.appspot.com/_api/download/file?downloadToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1cm46YXBwOjZlYTNhM2FjZjlkYjRkMmE4MzE5NjFhZGM1NGZkY2Q3Iiwib2JqIjpudWxsLCJhdWQiOlsidXJuOnNlcnZpY2U6ZmlsZS5kb3dubG9hZCJdLCJpc3MiOiJ1cm46YXBwOjZlYTNhM2FjZjlkYjRkMmE4MzE5NjFhZGM1NGZkY2Q3IiwiaWF0IjoxNTY1ODY2ODEwLCJqdGkiOiJhYThkMWE3MzNhNzkiLCJleHAiOjE1NjU4NjcxMjAsInBheWxvYWQiOnsicGF0aCI6Ii81ZTA2NjkzOC0yYmVlLTQ5ZWItYjM1MS1kOTNhNDRiY2E2Y2MvZjE1YmZiMDM4OWRkNDVjMzg3YWNmOGRlOGU5ZGU1YjQtcGRmLWV4YW1wbGUtdGVtcGxhdGUuanNvbiIsImV4cGlyeSI6MzAwLCJzYXZlQXMiOiJwZGYtZXhhbXBsZS10ZW1wbGF0ZS5qc29uIn19.gOX9vI7ns3x5BX0QHJOKk4SGV2QgRhGilPrFVnixVeI) file.

- Save the newly created template.

- Refresh the templates page to see your new pdf template.

- Copy the template’s ID to the ID field in the code in the **pdfGenerator.jsw** file.

- Publish your site.

The link returned from the call to the API is an external link. Since [wix-location.to()](https://www.wix.com/corvid/reference/wix-location.html#to) only works for external links on a published site, you will need to publish your site to see the generated PDF.

---

<div class="post-metadata">

**Author:** ![muratdemir-ist](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@muratdemir-ist](https://forum.wixstudio.com/u/muratdemir-ist)\
**Post date:** [August 15, 2019, 12:56pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/2 "2019-08-15T12:56:56Z")

</div>

Awesome 🙂

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [August 15, 2019, 3:28pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/3 "2019-08-15T15:28:38Z")

</div>

Hey Yisrael,

Thank you so much for the example.

As of now the link seems to be broken, are you still working on it?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [August 15, 2019, 3:41pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/4 "2019-08-15T15:41:34Z")

</div>

Just had that too, published site works fine, just can’t get the editor view link to work, probably just an error in the link.

Anyways, same as Shan, thanks for the great example, now that deserves a congratulatory drink somewhere nearby… 😉

---

<div class="post-metadata">

**Author:** ![Shan](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/shan/32/106059_2.png) [@Shan](https://forum.wixstudio.com/u/Shan)\
**Post date:** [August 15, 2019, 3:44pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/5 "2019-08-15T15:44:38Z")

</div>

@givemeawhisky Man honestly, we can’t thank Yisrael enough for what he does for us and the community at large.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 18, 2019, 9:03am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/6 "2019-08-18T09:03:54Z")

</div>

@givemeawhisky The link was fine but for some reason the template site was broken. It’s now fixed, and it’s time for drink.

---

<div class="post-metadata">

**Author:** ![av-promotional](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/av-promotional/32/2796_2.png) [@av-promotional](https://forum.wixstudio.com/u/av-promotional)\
**Post date:** [August 18, 2019, 9:17am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/7 "2019-08-18T09:17:05Z")

</div>

Please correct the link to an edit site. Having trouble completing the API connection.  
Thank you for all the helpful help and posts. Worth Paragon!

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 18, 2019, 9:21am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/8 "2019-08-18T09:21:43Z")

</div>

The link has been fixed.

---

<div class="post-metadata">

**Author:** ![av-promotional](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/av-promotional/32/2796_2.png) [@av-promotional](https://forum.wixstudio.com/u/av-promotional)\
**Post date:** [August 18, 2019, 9:21am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/9 "2019-08-18T09:21:57Z")

</div>

Thanks for the link fix.  
I’m still having trouble where do I put the API I got from PDF?  
And another small question, if possible, now that I see the code on an edit site, if I have a complex page am I supposed to compile all the parameters? Isn’t there a button that finds the entire page like a screenshot? Because I have squares and the like.  
Thank you for all the helpful help and posts. Worth Parag

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 18, 2019, 9:25am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/10 "2019-08-18T09:25:16Z")

</div>

The API is installed from the [Package Manager](https://support.wix.com/en/article/corvid-managing-external-code-libraries-with-the-package-manager) in the Editor.

---

<div class="post-metadata">

**Author:** ![muratdemir-ist](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@muratdemir-ist](https://forum.wixstudio.com/u/muratdemir-ist)\
**Post date:** [August 18, 2019, 11:42am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/11 "2019-08-18T11:42:29Z")

</div>

Hİ @yisrael-wix I have followed tutorial and checked all details on the sample page at the editor and publised but it is not working and gives error as it shown below;

 ![](https://us1.discourse-cdn.com/wix/original/3X/b/e/be0bcf956f3757fd39570a668a7b2a24fbc8e57e.png)  
(node:1) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

Did you get any this kind of error before?

I have seen also another issue but ı understand it is fine because it gives same error on your sample page at the editor site as it shown below;

 ![](https://us1.discourse-cdn.com/wix/original/3X/c/e/ceb90b7e0bf4dd6cf18a68dc0e8b103550ed21bd.png)  
Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value . It must be of type string.creat an offerLine 13

I would appreciate it, if you can answer about this issue when you have a free time 🙂 I know you are busy!! Thank you so much in advance…

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 18, 2019, 11:45am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/12 "2019-08-18T11:45:07Z")

</div>

The errors you are getting are from the NPM library. I would say that they’re OK, however errors are never OK. Let’s just say it’s beyond our control and it works.

---

<div class="post-metadata">

**Author:** ![muratdemir-ist](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@muratdemir-ist](https://forum.wixstudio.com/u/muratdemir-ist)\
**Post date:** [August 19, 2019, 9:28am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/13 "2019-08-19T09:28:38Z")

</div>

@yisrael-wix Thank you very much for your answer. I’ve tried everything and even edited your own sample with my information got it but it still doesn’t work. Do you think am ı missing something on backend code

 ![](https://us1.discourse-cdn.com/wix/original/3X/a/5/a5656748d0e900242404059875852162377aea5f.png)

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 19, 2019, 12:02pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/14 "2019-08-19T12:02:15Z")

</div>

@muratdemir-ist Enter in your account information (api key, secret, etc) without the brackets \< \>.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [August 19, 2019, 12:08pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/15 "2019-08-19T12:08:21Z")

</div>

You shouldn’t post your account credentials.

---

<div class="post-metadata">

**Author:** ![muratdemir-ist](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@muratdemir-ist](https://forum.wixstudio.com/u/muratdemir-ist)\
**Post date:** [August 19, 2019, 12:30pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/16 "2019-08-19T12:30:16Z")

</div>

@yisrael-wix i have made some changes before i posted 😉

---

<div class="post-metadata">

**Author:** ![muratdemir-ist](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@muratdemir-ist](https://forum.wixstudio.com/u/muratdemir-ist)\
**Post date:** [August 20, 2019, 7:36am UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/17 "2019-08-20T07:36:29Z")

</div>

Hi @yisrael-wix It is working now thank you so much for your support and exact backend code below;

import PDFGeneratorAPI from ‘pdf-generator-api’

const apiKey = ‘API KEY’;  
const apiSecret = ‘API SECRET’;  
const baseUrl = ‘[https://us1.pdfgeneratorapi.com/api/v3/](https://us1.pdfgeneratorapi.com/api/v3/)’;  
const workspace = ’ your e-mail address used on pdf generator api to creat an account’;  
const templateID = ‘Templete Id’;

let Client = **new** PDFGeneratorAPI(apiKey, apiSecret)  
Client.setBaseUrl(baseUrl)  
Client.setWorkspace(workspace)

**export async function** getPdfUrl(data) {  
const {response} = **await** Client.output(templateID, data, undefined, undefined, {output: ‘url’})  
**return** response  
}

---

<div class="post-metadata">

**Author:** ![info47516](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/info47516/32/16639_2.png) [@info47516](https://forum.wixstudio.com/u/info47516)\
**Post date:** [January 8, 2020, 6:24pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/18 "2020-01-08T18:24:31Z")

</div>

Awesome!

I have just a question:

Can I add an image to the PDF using the form? For example, the user browsing the site would like to insert his logo in the PDF, how can you do that?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [January 8, 2020, 6:44pm UTC](https://forum.wixstudio.com/t/example-pdf-generator/22504/19 "2020-01-08T18:44:53Z")

</div>

You can change the template yourself through your own account in the third party.  
[https://pdfgeneratorapi.com/](https://pdfgeneratorapi.com/)
