Giter Club home page Giter Club logo

pdf-ghost-report's Introduction

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-]

pdf-ghost-report's People

Contributors

dependabot[bot] avatar larbibaraka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pdf-ghost-report's Issues

How to generate pdf from markdown ?

This should be a pull request not an issue.

Feature: Auto-generate pdf from Readme.md

Description: A bot or script that generates pdf automatically from Readme each time I commit.

Why?

I don't want to generate pdfs manually.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.