JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q18290F
  • License MIT

Package Exports

  • pdf-ghost-report

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pdf-ghost-report) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

pdf-ghost-report

an open source solution for your nodejs reporting

Version npm npm Downloads 'License'

NPM

Usage

// example using express web framework
const express = require('express');
const { generatePdf } = require('pdf-ghost-report');
router = express.Router();
router.post('/getpdf', async (req, res, next) => {
  // step 01 : get template name
  const template_name = 'template_name';
  const data = req.body;
  // step 02 : call pdf making function by passing the template folder and name
  const config = {
    emulator: 'screen' || 'print',
    printBackground: true,
    format: 'A4',
    margin: {
      top: '50px',
      bottom: '50px',
      left: '20px',
      right: '20px',
    },
    displayHeaderFooter: true,
  };
  /**
   * args :
   *  templateFolderPath: string,
   *  templateFileName: string,
   *  templateExtension: string,
   *  config: object,
   *  data: object
   *
   * return stream
   * */
  const pdf = await generatePdf('templates', 'test', 'hbs', config, data);
  // // step 03 : return the blob pdf stream to the client
  res.writeHead(200, {
    'Content-Type': 'application/pdf',
    'Content-Disposition': `attachment; filename=${template_name}.pdf`,
    'Content-Length': pdf.length,
  });
  res.end(pdf);
});
module.exports = router;

config

For more config Info check Puppeteer pdf section

Installation

npm install pdf-ghost-report
yarn add pdf-ghost-report

Run Tests

  • for now we haven't created any test
npm test

Todo

[ ] add tests
[ ] add docker
[ ] support more template engins like : `ejs, ...etc`

Author: [BARAKA LARBI -laridev-]