How to use html-pdf - 9 common examples

To help you get started, we’ve selected a few html-pdf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codeforsanjose / SJPL-MealTally / lib / pdfCreator.js View on Github external
return new Promise((resolve, reject) => {
        // get the template with the data added to it
        var resultHTML = template({ meals: data })
        if (resultHTML && data) { // if we have both data and a resulting html from executing the template
            var today = new Date()
            var year = today.getFullYear() + 1
            var month = today.getMonth() + 1
            var day = today.getDate()
            var filePath = "./reports/report-" + year + "-" + month + "-" + day + ".pdf"
            var fileName = "report-" + year + "-" + month + "-" + day + ".pdf"
            // create the pdf landscape to fit the table
            pdf.create(resultHTML, { format: 'Letter',"orientation": "letter" }).toFile(filePath, function(error, result){
                // create file to send pdf file back to user does not take up space on our server
                if (error) { // report pdf creation error
                    console.log("Could not create PDF")
                    console.log(error)
                    return reject(error)
                }
                return resolve(fileName)
            })
        } else { // report the lack of data or output or both
            return reject("no report data")
        }
    })
}
github navjotdhanawat / dynamic-html-pdf / index.js View on Github external
return new Promise((resolve, reject) => {

        if (!document || !document.template || !document.context) {
            reject(new Error("Some, or all, options are missing."));
        }

        if (document.type !== 'buffer' && !document.path) {
            reject(new Error("Please provide path parameter to save file or if you want buffer as output give parameter type = 'buffer'"));
        }

        var html = Handlebars.compile(document.template)(document.context);
        var pdfPromise = pdf.create(html, options);
        if (document.type === 'buffer') {
            // Create PDF from html template generated by handlebars
            //Output will be buffer
            pdfPromise.toBuffer((err, buff) => {
                if (!err)
                    resolve(buff);
                else
                    reject(err);
            });
        } else {
            // Create PDF from html template generated by handlebars
            // Output will be PDF file
            pdfPromise.toFile(document.path, (err, res) => {
                if (!err)
                    resolve(res);
                else
github opencollective / opencollective-frontend / src / server / routes.js View on Github external
app.renderToHTML(req, res, '/nametags', params).then(html => {
      if (format === 'html') {
        return res.send(html);
      }

      const options = {
        pageFormat: pageFormat === 'A4' ? 'A4' : 'Letter',
        renderDelay: 3000,
      };
      // html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,'');
      const filename = `${moment().format('YYYYMMDD')}-${collectiveSlug}-${eventSlug}-attendees.pdf`;

      res.setHeader('content-type', 'application/pdf');
      res.setHeader('content-disposition', `inline; filename="${filename}"`); // or attachment?
      pdf.create(html, options).toStream((err, stream) => {
        if (err) {
          logger.error('>>> Error while generating pdf at %s', req.url, err);
          return next(err);
        }
        stream.pipe(res);
      });
    });
  });
github Zach417 / churchetto-web / server / router / exports / taxStatement / index.js View on Github external
memberHtml = memberHtml.replace("{TOTAL_CONTRIBUTIONS}","Total Contributions: $" + parseFloat(totalContributions).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'))

      memberHtml = memberHtml.replace("{FOOTER}","No goods or services were provided in return for these contributions, other than intangible religious benefits.");

      if (i + 1 === church.members.length) {
        memberHtml = memberHtml.replace("<div class=\"member member-margin\">","<div class=\"member-margin\">");
      }

      members = members + memberHtml;
    });

    html = html.replace('{MEMBERS}',members);

    //res.send(html);
    pdf.create(html, options).toStream(function(err, stream){
      if (err) return console.log(err);
      stream.pipe(res);
    });
  });
github sneas / cv-project / src / utils / pdf.js View on Github external
return new Promise((resolve, reject) => {
    pdf.create(html, options).toFile(output, function (err) {
      if (err) {
        console.log(err);
        reject(err);
      }
      resolve();
    });
  })
}
github macarthur-lab / gnomadjs / packages / export-pdf / src / index.js View on Github external
const generatePDF = (html, fileName) => {
  try {
    pdf.create(html).toFile(`${temp}/${fileName}`, (error, response) => {
      if (error) {
        module.reject(error)
      } else {
        console.log(response)
        module.resolve({ fileName, base64: getBase64String(response.filename) })
      }
    })
  } catch (exception) {
    module.reject(exception)
  }
}
github Zach417 / churchetto-web / server / router / exports / deceasedReport / index.js View on Github external
members = members
      + "<tr style='font-size:14px;'>"
        + "<td style='padding: 2px 5px;'>"
          + member.lastName
          + ", " + member.firstName
        + "</td>"
        + "<td style='padding: 2px 5px;'>"
          + moment(member.dateOfDeath).format("MM/DD/YYYY")
        + "</td>"
      + "</tr>";
    });
    html = html.replace('{MEMBERS}',members);

    //res.send(html);
    pdf.create(html, options).toStream(function(err, stream){
      if (err) return console.log(err);
      stream.pipe(res);
    });
  });
github Zach417 / churchetto-web / server / router / exports / birthdayReport / index.js View on Github external
members = members
      + "<tr style='font-size:14px;'>"
        + "<td style='padding: 2px 5px;'>"
          + member.lastName
          + ", " + member.firstName
        + "</td>"
        + "<td style='padding: 2px 5px;'>"
          + moment(member.dateOfBirth).format("MM/DD/YYYY")
        + "</td>"
      + "</tr>";
    });
    html = html.replace('{MEMBERS}',members);

    //res.send(html);
    pdf.create(html, options).toStream(function(err, stream){
      if (err) return console.log(err);
      stream.pipe(res);
    });
  });
github tanhauhau / express-pdf / index.js View on Github external
return new Promise(function(resolve, reject){
        setHeader(res, filename);
        pdf.create(content, options).toStream(function(err, stream){
            if(err){
                reject(err);
            }else{
                stream.pipe(res);
                stream.on('end', function(){
                    res.end();
                    resolve();
                })
            }
        });
    });
}

html-pdf

HTML to PDF converter that uses phantomjs

MIT
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis

Popular html-pdf functions

Popular JavaScript code snippets

Find secure code to use in your application or website