# pdf creation help

**URL:** <https://forum.wixstudio.com/t/pdf-creation-help/1603>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 9, 2021, 8:30pm UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603 "2021-02-09T20:30:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jana9340](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jana9340/32/26327_2.png) [@jana9340](https://forum.wixstudio.com/u/jana9340)\
**Post date:** [February 9, 2021, 8:30pm UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/1 "2021-02-09T20:30:15Z")

</div>

Hi all,

Total nube here. I’m reasonably familiar with the front end of Wix, but currently am learning and know just enough to be really dangerous with some backend things.

I’m creating a page where the user can make their own Lost / Found poster. I’ve checked out the tutorial here: [https://www.wix.com/velo/forum/tips-tutorials-examples/example-pdf-generator](https://www.wix.com/velo/forum/tips-tutorials-examples/example-pdf-generator)

I have made the pdf template with 4 fields in it: petDescription, whereWhen, contactInfo, phone. It’s published and ready to go.

The NPM installed no problem.

Back end code (pdf.jsw) is:

import PDFGeneratorAPI from ‘pdf-generator-api’

const apiKey = ‘blah blah blah’ ;  
const apiSecret = ‘blah blah blah’ ;  
const baseUrl = ‘[https://us1.pdfgeneratorapi.com/api/v3/](https://us1.pdfgeneratorapi.com/api/v3/)’ ;  
const workspace = ‘blah blah blah’  
;  
const templateID = ‘123456’  
;

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  
}

On the page where the user canmake their own poster, I’ve set each input component up (# petDescription, #whereWhen, #contactInfo, #phone) as well as a Submit button (#button1). #button1 is defined as an event: generatePoster\_click. There is a second button (#button2) which opens the completed pdf page (or at least that’s the plan).

I’m running into trouble with the code on that page. I currently have:

import { pdf } from ‘backend/pdf.jsw’ ;

**export async function** generatePoster\_click(event) {petDescription, whereWhen, contactInfo, phone}  
const petDescription = $w( ‘#petDescription’ );  
const whereWhen = $w( ‘#whereWhen’ );  
const contactInfo = $w( ‘#contactInfo’ );  
const phone = $w( ‘#phone’ );

const pdfUrl = **await** getPdfUrl({petDescription, whereWhen, contactInfo, phone});  
$w( “#button2” ).link = pdfUrl;  
$w( “#button2” ).target = “\_blank” ;  
$w( “#button2” ).label = “Open PDF” ;  
$w( “#button2” ).show();  
}

I’m getting an error that the ‘await’ is outside the async. And I may have other issues that I’m unaware of.

Help and solutions would be appreciated!

Thanks

Jana

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [February 10, 2021, 12:38am UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/2 "2021-02-10T00:38:16Z")

</div>

Delete the part in red:

```javascript
export async function generatePoster_click(event) {petDescription, whereWhen, contactInfo, phone}

```

---

<div class="post-metadata">

**Author:** ![jana9340](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jana9340/32/26327_2.png) [@jana9340](https://forum.wixstudio.com/u/jana9340)\
**Post date:** [February 10, 2021, 12:42am UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/3 "2021-02-10T00:42:58Z")

</div>

I’ll try that – thanks!

---

<div class="post-metadata">

**Author:** ![jana9340](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jana9340/32/26327_2.png) [@jana9340](https://forum.wixstudio.com/u/jana9340)\
**Post date:** [February 10, 2021, 12:49am UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/4 "2021-02-10T00:49:32Z")

</div>

Hi JD,

I made the change and it got rid of the error re: outside the async. But it created another. On line 4, the error highlights ‘const’ and says it is a “Parsing error: unexpected token”

**1 import** { pdf } **from** ‘backend/pdf.jsw’ ;  
2  
3 **export async function** generatePoster\_click(event)  
4 **const** petDescription = $w( ‘#petDescription’ );  
5 **const** whereWhen = $w( ‘#whereWhen’ );  
6 **const** contactInfo = $w( ‘#contactInfo’ );  
7 **const** phone = $w( ‘#phone’ );  
8  
9 **const** pdfUrl = **await** getPdfUrl({petDescription, whereWhen, contactInfo, phone});  
10 $w( “#button2” ).link = pdfUrl;  
11 $w( “#button2” ).target = “\_blank” ;  
12 $w( “#button2” ).label = “Open PDF” ;  
13 $w( “#button2” ).show();  
14 }

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [February 10, 2021, 1:11am UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/5 "2021-02-10T01:11:02Z")

</div>

@jana9340 add a **{** in the end of line 3.

---

<div class="post-metadata">

**Author:** ![jana9340](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jana9340/32/26327_2.png) [@jana9340](https://forum.wixstudio.com/u/jana9340)\
**Post date:** [February 10, 2021, 3:39pm UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/6 "2021-02-10T15:39:53Z")

</div>

@jonatandor35 Thanks JD, you’ve been very helpful!

Can I bug you for another query?

After inserting the {, the error resolved, but of course a new one popped up. 🙂

On the page code, I’m getting an ‘undefined element’ error on the getPdfUrl (after await in line 9). On the back end code, I’m not getting the same error about the undefined element. (snippet below)

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

Help is welcome, and if there’s a link to a tutorial I should check instead of bugging you, that’d be great also. 🙂

jana

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [February 10, 2021, 11:14pm UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/7 "2021-02-10T23:14:42Z")

</div>

@jana9340 I don’t see where you’re importing the getPdfUrl to the front-end.

---

<div class="post-metadata">

**Author:** ![jana9340](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jana9340/32/26327_2.png) [@jana9340](https://forum.wixstudio.com/u/jana9340)\
**Post date:** [February 11, 2021, 8:40pm UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/8 "2021-02-11T20:40:48Z")

</div>

@jonatandor35 Thanks! I added it in a the error resolved.

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [February 11, 2021, 9:59pm UTC](https://forum.wixstudio.com/t/pdf-creation-help/1603/9 "2021-02-11T21:59:54Z")

</div>

You’re welcome 🙂  
Maybe you should post your final code here to help other forum visitors.
