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
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/’ ;
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