New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

nodejs-pdf-report

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodejs-pdf-report

nodejs server export pdf from base html template

latest
npmnpm
Version
1.1.4
Version published
Maintainers
1
Created
Source

nodejs-pdf-report

Nodejs export pdf report from base html templates!

NPM version npm download

Install

nodejs-pdf-report

npm install --save nodejs-pdf-report

Supports

  • Base html template with EJS engine.
  • Embeded Chart.js v2.9.3.
  • Server side without browser.

Examples

  • Import from package
   import { HtmlReport, ReportOptions } from "nodejs-pdf-report";
  • Define configures
const reportOptions: ReportOptions = {
  title: "Test report with chartjs",
  useChartJs: true,
  pdfOptions: {
    margin: {
      top: "100px",
      bottom: "200px",
      right: "30px",
      left: "30px",
    },
  },
  template: "template.ejs",
  headerTemplate: "header-template.ejs",
  footerTemplate: "footer-template.ejs",
  styles: [
      "styles.css"
  ],
  scripts: [
    "utils.js",
    "index.js",
  ],
  data: {
    users: [
        {
            name: "Luong Phung",
        },
        {
            name: "Jasmine",
        },
    ],
    title: "Test report with chartjs",
    author: "Luong Phung",
    time: "2020",
  },
};
  • Create pdf file as buffer
  const htmlReport = new HtmlReport();
  const reportPdf = await htmlReport.createPdf(reportOptions);
  const savePath = path.resolve("./chartjs_report.pdf");
  fs.writeFileSync(savePath, reportPdf, "binary");
  • Check you report file "chartjs_report.pdf"

Screen shots

screen shot

API references

PdfOptions

NametypedefaultDescription
scalenumber1Scale of the webpage rendering
printBackgroundbooleanfalsePrint background graphics.
landscapebooleanfalsePaper orientation
formatstring"A4"Page format as : "Letter" "A0" ... "A4" ...
margin{top, bottom, left, right}{0, 0, 0, 0}Page margin as number of pixels

ReportOptions

NametypedefaultDescription
titlestringnullPdf report title
useChartJsbooleanfalseUse chartjs as default
pdfOptionsPdfOptionsnullany
templatestringnullTemplate path
footerTemplatestringnullFooter template path
headerTemplatestringnullHeader template path
stylesstring[][]Style paths
scriptsstring[][]Scripts paths
dataobject{}Report data

License

nodejs-pdf-report is released under the MIT license.

Keywords

node

FAQs

Package last updated on 24 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts