1.2.8 • Published 2 years ago

@rossbob/html-to-pdf v1.2.8

Weekly downloads
274
License
MIT
Repository
github
Last release
2 years ago

nHTMLToPDF

Node lib to converts HTML with property binding or url to PDF files

Installation

$ npm install @rossbob/html-to-pdf

Unit Test

  • Jest
  • Coverage : 100%

Usage

async function main() {
  const browser = await initBrowser();

  try {
    const { pdfs } = await generatePDF(browser, files);
    const { pdf } = await generatePDF(browser, file);

    const stream = fs.createWriteStream(`./${your_pdf_name}.pdf`);

    stream.write(pdf.buffer); // => create file for the given buffer.
    
    for (let pdf of pdfs) {
      stream.write(pdf.buffer); // => create file for each given buffer
    }
  }
  finally {
    await terminateBrowser(browser);
  }
}

main().catch(console.error);

initBrowser(): Promise

async function main() {
  const browser = await initBrowser();
}
main().catch(console.error);

generatePDF(browser: Browser, files: pdfFile[], options?: PDFOPtions): Promise

interface pdfFile {
  content?: string,
  url?: string,
  options?: {}
}

More Info [there](https://pptr.dev/#?product=Puppeteer&version=v7.1.0&show=api-pagepdfoptions)
interface PDFOptions {
  path?: string,
  scale?: number,
  displayHeaderFooter?: boolean,
  headerTemplate?: string,
  footerTemplate?: string,
  printBackground?: boolean,
  landscape?: boolean,
  pageRanges?: string,
  format?: string,
  width?: string | number,
  height?: string | number,
  margin?: {
    top?: string | number,
    right?: string | number,
    bottom?: string | number,
    left?: string | number,
  },
  preferCSSPageSize?: boolean
}

interface PDF {
  options?: string,
  buffer: Buffer
}

interface genPDFPayload {
  pdf?: PDF,
  pdfs?: PDF[],
  stream?: fs.ReadStream
}
async function main() {
  const browser = await initBrowser();
  const result = await generatePDF(browser, files);
}
main().catch(console.error);

terminateBrowser(browser: Browser): Promise

async function main() {
  const browser = await pdf.initBrowser();
  await terminateBrowser(browser);
}
main().catch(console.error);

How to use Zup

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago