How to use html-pdf-chrome - 6 common examples

To help you get started, we’ve selected a few html-pdf-chrome 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 steinslin / note / index.js View on Github external
// pdf.create(html, {
//   format: 'A4'
// }).toFile('./profile.pdf', (err, result) => {
//   if (err) {
//     return console.error(err)
//   }
//   console.log(result)
// })

const htmlPdf = require('html-pdf-chrome')

const options = {
  // port: 9222, // port Chrome is listening on
};

htmlPdf.create(html, options).then(pdf => pdf.toFile('./profile.pdf'))


function p () {
  setTimeout(() => {
    console.log('settimeout 0')
  }, 0)
  window.requestAnimationFrame(() => {
    console.log('request')
  })
  setTimeout(() => {
    console.log('settimeout 0')
  }, 0)
  setTimeout(() => {
    console.log('settimeout 17')
  }, 17)
}
github esbenp / pdf-bot / src / pdfGenerator.js View on Github external
return function createPdf (url, job) {
    debug('Creating PDF for url %s with options %s', url, JSON.stringify(options))

    var generationId = uuid()
    var generated_at = utils.getCurrentDateTimeAsString()
    var jobId = job.id

    function createResponseObject() {
      return {
        id: generationId,
        generated_at: generated_at
      }
    }

    return htmlPdf
      .create(url, options)
      .then((pdf) => {
        var pdfPath = path.join(storagePath, 'pdf', (uuid() + '.pdf'))

        debug('Saving PDF to %s', pdfPath)

        return pdf
          .toFile(pdfPath)
          .then(function(response){
            var storage = {
              local: pdfPath
            }
            var storagePluginPromises = []
            for (var i in storagePlugins) {
              // Because i will change before the promise is resolved
              // we use a self executing function to inject the variable
github esbenp / pdf-bot / examples / pdf-bot.config.js View on Github external
var htmlPdf = require('html-pdf-chrome')
var createS3Config = require('../src/storage/s3')
var pgsql = require('../src/db/pgsql')

module.exports = {
  api: {
    token: 'api-token'
  },
  db: pgsql({
    user: 'pdfbot',
    password: 'pdfbot',
    database: 'pdfbot'
  }),
  // html-pdf-chrome options
  generator: {
    completionTrigger: new htmlPdf.CompletionTrigger.Timer(1000), // waits for 1 sec
    //port: 50 // chrome port
  },
  queue: {

  },
  storage: {
    /*'s3': createS3Config({
      bucket: '',
      accessKeyId: '',
      region: '',
      secretAccessKey: ''
    })*/
  },
  // storagePath: '',
  webhook: {
    headerNamespace: 'X-PDF-',
github carlos-kelly / publications / src / platform / handlers / pdf.ts View on Github external
export default async function documentPdfHandler(req: Request, res: Response) {
  const { document } = req.body;
  try {
    const completionTrigger = new htmlPdf.CompletionTrigger.Timer(2000);
    const documentHtml = generateHtmlFromDocument(document as any);
    const { width, height } = document.pages[0] as PubPage;
    const isLandscape = width > height;
    const pdf = await htmlPdf.create(
      `
      ${baseHtml}
      <div>
        ${documentHtml}
      </div>
    `,
      {
        port: 9922,
        completionTrigger,
        printOptions: {
          ...basePrintOptions,
          landscape: isLandscape,
          paperWidth: isLandscape ? height : width,
          paperHeight: isLandscape ? width : height,
github danielwestendorf / breezy-pdf-lite / lib / render.js View on Github external
toPdf() {
    const renderOptions = {
      completionTrigger: this.completionTrigger(),
      printOptions:      this.printOptions(),
      host:              'localhost',
      port:              9222
    }

    this.log(`Generating PDF for HTML string with options: ${JSON.stringify(renderOptions)}`)

    return htmlPdf.create(this.htmlString, renderOptions)
  }
github carlos-kelly / publications / src / platform / handlers / pdf.ts View on Github external
export default async function documentPdfHandler(req: Request, res: Response) {
  const { document } = req.body;
  try {
    const completionTrigger = new htmlPdf.CompletionTrigger.Timer(2000);
    const documentHtml = generateHtmlFromDocument(document as any);
    const { width, height } = document.pages[0] as PubPage;
    const isLandscape = width &gt; height;
    const pdf = await htmlPdf.create(
      `
      ${baseHtml}
      <div>
        ${documentHtml}
      </div>
    `,
      {
        port: 9922,
        completionTrigger,
        printOptions: {

html-pdf-chrome

HTML to PDF and image converter via Chrome/Chromium

MIT
Latest version published 1 year ago

Package Health Score

61 / 100
Full package analysis