How to generate PDF in JS?

  • 0
    Hello, there was a question about generating PDF documents. It is necessary to generate a PDF based on JSON or HTML, considered 2 options, on the back with puppeteer , and on the front using jsPDF or Print.js , I stick to the option on the back, because there are a lot of documents, and their number is likely to grow, and I don't really want to drag all the templates to the front, and everything is not very good with the encoding in jsPDF. Actually, what approach is more correct to use? Maybe there is some option that is not obvious to me?
    JavaScript Evangeline Watts, Jun 14, 2019

  • 5 Answers
  • 0
    From experience I will say that it is better to use full-fledged tools for generating PDF than options with automatic conversion of html to pdf. I would recommend pdfkit.org
    Anonymous

  • 0
    Of the options proposed by the author, it is definitely puppeteer. At the front, you will start to suffer with cross-browser code, limits (multi-page pdfs will take you by surprise), and quality - at the front, as a rule, html = & gt; raster = & gt; pdf and everything floats when enlarged. puppeteer (via chromium) keeps an honest vector where appropriate. Yes, and html layout will not have to be done for an army of browsers, but only for the chromium of a previously known version.
    Anonymous

  • 0
    there are many options on the front, on the back the most "accurate" option will be the option with headless chrome, or something like a pupitir, all the rest are quite buggy and do not support normal layout. As mentioned by Semyon Kuznetsov - a simple option - printing in pdf from chrome, in fact, this is almost analogous to headless chrome on the backend, only on the front ... If this is not a commercial product for paid users, then this option is generally out of competition.
    Anonymous

  • 0
    Do you need massive generation?

    That is, to generate for some reason, I can't even imagine why, a hundred pdf. Or is it elementary that some manager would press the download button and receive a PDF file, for example, with statistics?
    Anonymous

  • 0
    There is also another option (on a clean backend): prepare templates in advance in PDF format with all static data (for example, bank details). When requesting a download, add to the empty fields and give the file. And you don't have to fool around generating PDFs from scratch. appending data to an existing PDF is an easy operation. They did just that on sale.
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!