Generate PDF with PDFgeneratorAPI gives Error

Hello,

i’m looking for a way for users to download a pdf of a custom order they placed. now i whas following this tutorial from @salman-hammed
https://www.wix.com/corvid/forum/community-discussion/pdf-generator-api-npm-demo i followed it just as he explained but i get this error


Error loading web module backend/pdf.jsw: Cannot find module 'pdf-generator-api' Require stack: - /user-code/backend/pdf.jsw - /user-code/stubmodule-that-does-the-require.js - /elementory/node_modules/scoped-require/index.js - /elementory/create-app.js - /elementory/cloud-grid-runner.js

Here are some images of my code:

the html code is exactly the same as in the tutorial (not visible on the images)
Any idea what i am doing wrong?

any help is appreciated

kind regards
kristof.

Hi Kristof,
I’m moving this into our Community Discussion category, which is where you can get help for your question. Thanks!

I will try this feature today.
#Following

Hello @volkaertskristof
Looks like a wix bug
I will forward to wix and
in the mean time
try to save and reload the editor
And see if that fixed?

Hello @salman-hammed
Thanks for taking a look
I tried saving, reloading, used new inputfield, copyed the html code and pdf.jsw code again without succes

If i find the time today i will try it again but tomorrow is my wedding so lots to do today :sweat_smile:

@volkaertskristof no hurry and Congrats dude :tada:

@volkaertskristof can you try un-installing pdf-generator-api and re-install it?

@harelmoshe @salman-hammed
I tried reinstaling it before and didn’t work.
now today when i started my website and tried it it suddenly worked.
now when i looked on the pdfgeneratorapi website i sa that there is a limit of 500 downloads a month.
otherwhise its 59$.
is there an free alternative for it to have more then 500 downloads?
or is there a way to just download the page as pdf?
i should also be able to save it to the website so they can download it later.

kristof.

@volkaertskristof There is a free alternative but i don’t have a tutorials on it
check out http://pdfmake.org/
but it will require to write code to create the PDF
you cannot use the drag and drop like in pdf generator api site

@salman-hammed
Thanks for the link,
i will take a look and hope to figure out how it works.
the drag and drop from PDFgeneratorAPI is a nice feature but is not realy needed.
its just to have an order lst for our customers.
If i find a way to make it work i might make a tutorial myself and you can share it on your website.

kristof.

Congrats sir! :heart_eyes:

You can try pressing “ctrl+p” the user can either print or save it as pdf.
As of now that is what i am doing. I just layout my page to have a print ready layout hehe

Thanks @jeffersonuy
i have tought of that idea to.
its easy and straight forwad
but

  1. atm not all the details the customers need are on my website.
  2. i want to be able to send it by mail later on to so they can easly download it on their mobile phone if needed.
    so its an option for now but for the future i really would need the pdf to be able to downloade.

kristof.

@salman-hammed
any idea what i am doing wrong here?

i imported the pdfmake
defined is as pdfMake
used the code to “download” the pdf
getting this error.

kristof.

hi kristof, i found simple npm pdf maker . https://github.com/MrRio/jsPDF
you can embed it inside an html element as i did :

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <title>Document</title>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js" integrity="sha384-NaWTHo/8YCBYJ59830LTz/P4aQZK1sS0SneOgAvhsIl3zBu8r9RevNg5lHCHAuQ/" crossorigin="anonymous"></script>

</head>
<body>
 <div>can you print me please???</div>
 
 <script>
 var doc = new jsPDF();          
var elementHandler = {
 '#ignorePDF': function (element, renderer) {
 return true;
  }
};
var source = window.document.getElementsByTagName("body")[0];
doc.fromHTML(
 source,
 15,
 15,
    {
 'width': 180,'elementHandlers': elementHandler
    });
 ///you can also save the doc file with doc.save();

doc.output("dataurlnewwindow");
 
 </script>
</body>
</html>

if you want to dynamically print different pdfs you can create div element inside the body and then manipulate its innerHTML as you wish → append it to the body element ->query selector it varsource=window.document.querySelector(“my-amazing-div”); → load it with doc.fromHTML and then save it with doc.save()

Hi! I tried this but seems that for Chrome is not possible to download anything enveloped by an iframe tag:
https://www.chromestatus.com/feature/5706745674465280
Is there any way of changing the iframe tag in order to add ‘allow-downloads’ flag from the htmlElement?

Hi @anasanchez1b10 ,

I have stumbled upon this problem to.
J.D. told me that if you use a custom element (premium users)
and use an iframe in there it should work.

i’m going to try it today, but don’t know where to start yet.