puppeteer#PDFOptions TypeScript Examples

The following examples show how to use puppeteer#PDFOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Pdf.ts    From pdf-generator-service with MIT License 6 votes vote down vote up
private static buildPdfArguments(options: PdfOptions, toc: boolean): PDFOptions {
    return {
      format: options.format,
      landscape: options.orientation == 'landscape',
      margin: options.margin,
      printBackground: true,
      displayHeaderFooter: toc ? false : options.displayHeaderFooter,
      headerTemplate: options.header,
      footerTemplate: options.footer,
    }
  }
Example #2
Source File: Pdf.spec.ts    From pdf-generator-service with MIT License 6 votes vote down vote up
async function testPdfParam(options: Partial<PdfOptions>, pdfOptions: PDFOptions) {
  browserProto.newPage.mockClear()
  pageProto.close.mockClear()
  pageProto.pdf.mockClear()

  const mockedPuppeteer = mocked(puppeteer)
  const browser = await mockedPuppeteer.launch()
  const pdf = new Pdf(browser)
  await pdf.generate(pdfOptionsFactory(Object.assign({ content: '<h2>Hello</h2>' }, options)))
  expect(browserProto.newPage).toBeCalledTimes(1)
  expect(pageProto.pdf).toBeCalledTimes(1)
  expect(pageProto.close).toBeCalledTimes(1)
  expect(pageProto.pdf).lastCalledWith(expect.objectContaining(pdfOptions))
}