node-pdf-report
v1.1.0
Published
node-pdf-report is a HTML(ejs) to PDF and Image coverting library, this library is powered by puppeteer PDF reporting facilities.
Downloads
52
Readme
Features
- Pure HTML or ejs Template to PDF, PNG and JPEG Conversion.
- Create File or Get Buffer/Base64 For Further Usage.
- Json to HTML Conversion.
- Typescript Support.
Installation
$ npm install node-pdf-report
ejs Sample Template
<body>
<h1>
<%= name %>
</h1>
</body>
Code Example
const { createPDF, getPDFBuffer, jsonObjectToHTML, getImage, createImage} = require('node-pdf-report');
/**
* get PDF as Buffer for further use
* options = {
* relativePath: <ejs template relative path>
* data: <object to be passed in template>
* format: <puppteer compatible any pdf format>
* html: <direct HTML content>
*
* }
*/
const pdfBuffer = await getPDFBuffer({
html: '<body><h3>Hello world</h3></body>'
});
console.log(pdfBuffer)
/**
* Create PDF from html or ejs
* options = {
* relativePath: <ejs template relative path>
* data: <object to be passed in template>
* format: <puppteer compatible any pdf format>
* html: <direct HTML content>
* outPath: <path of output>
* }
*/
await createPDF({
relativePath: './templates/basic.html',
data: { name: "Nahid Chowdhury" },
outPath: './pdf/mypdf.pdf'
});
/**
* Json to html report
*/
const html = jsonObjectToHTML({
name: "Nahid Chowdhury",
age: 26,
others: {
profession: 'Software Engineer',
company: 'ERA InfoTech LTD'
}
})
createPDF({
html: html,
outPath: './pdf/fromJson.pdf'
})
/**
* Get Image from html or ejs (In Base64 or Binary)
* options = {
* relativePath: <ejs template relative path>
* data: <object to be passed in template>
* html: <direct HTML content>
* type: <jpeg or png>
* encoding: <base64 or binary>
* }
*/
const imageBase64 = await getImage({
relativePath: './templates/basic.html',
data: { name: "Nahid Chowdhury Ovi" },
type: 'jpeg',
encoding: 'base64'
});
/**
* Create Image from html or ejs (png or jpeg)
* options = {
* relativePath: <ejs template relative path>
* data: <object to be passed in template>
* html: <direct HTML content>
* outPath: <output image path with image name (png and jpeg extension supported)>
* }
*/
createImage({
relativePath: './templates/basic.html',
data: { name: "Nahid Chowdhury Ovi" },
outPath: './pdf/image.png'
})
Stay in touch
- Author - Nahid Chowdhury
License
Node PDF Report is MIT licensed.