Example: PDF Generator

Demonstrates

Links for this example

About this example

This example uses the PDF Generator API 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 in the Editor, install the pdf-generator-api NPM library.

  • Open a PDF Generator API sandbox account .

  • 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 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() only works for external links on a published site, you will need to publish your site to see the generated PDF.

10 Likes

Awesome :slight_smile:

1 Like

Hey Yisrael,

Thank you so much for the example.

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

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… :wink:

2 Likes

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

5 Likes

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

3 Likes

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!

The link has been fixed.

1 Like

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

The API is installed from the Package Manager in the Editor.

@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;


(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;


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 :slight_smile: I know you are busy!! Thank you so much in advance…

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.

@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

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

You shouldn’t post your account credentials.

@yisrael-wix i have made some changes before i posted :wink:

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

1 Like

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?

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