https://github.com/krakenui/octopus-pdf
Nodejs export pdf report from base html templates by KrakenTeam!
https://github.com/krakenui/octopus-pdf
chartjs2pdf html html2pdf htmlpdf htmlreport kraken node octopus pdf report
Last synced: 3 months ago
JSON representation
Nodejs export pdf report from base html templates by KrakenTeam!
- Host: GitHub
- URL: https://github.com/krakenui/octopus-pdf
- Owner: krakenui
- Created: 2020-07-24T10:17:44.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-03T07:42:00.000Z (over 1 year ago)
- Last Synced: 2025-02-22T11:32:33.360Z (3 months ago)
- Topics: chartjs2pdf, html, html2pdf, htmlpdf, htmlreport, kraken, node, octopus, pdf, report
- Language: TypeScript
- Homepage: https://docs.krakenui.com/octopus-pdf
- Size: 819 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# octopus-pdf
Nodejs export pdf report from base html templates!
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]
[npm-image]: http://img.shields.io/npm/v/octopus-pdf.svg?style=flat-square
[npm-url]: http://npmjs.org/package/octopus-pdf
[download-image]: https://img.shields.io/npm/dm/octopus-pdf.svg?style=flat-square
[download-url]: https://npmjs.org/package/octopus-pdf## Install
[](https://npmjs.org/package/octopus-pdf)
```
npm install --save octopus-pdf
```## Supports
- Base html template with [EJS](https://github.com/mde/ejs) engine.
- Embeded [Chart.js v2.9.3](https://www.chartjs.org).
- Server side without browser.## Examples
- Import from package
```
import { HtmlReport, ReportOptions } from "octopus-pdf";
```- 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

## API references
### PdfOptions
| Name | type | default | Description |
| --------------- | -------------------------- | ------------ | ------------------------------------------- |
| scale | number | 1 | Scale of the webpage rendering |
| printBackground | boolean | false | Print background graphics. |
| landscape | boolean | false | Paper orientation |
| format | string | "A4" | Page format as : "Letter" "A0" ... "A4" ... |
| margin | {top, bottom, left, right} | {0, 0, 0, 0} | Page margin as number of pixels |### ReportOptions
| Name | type | default | Description |
| -------------- | -------------------------- | ------- | ---------------------- |
| title | string | null | Pdf report title |
| useChartJs | boolean | false | Use chartjs as default |
| pdfOptions | [PdfOptions](#PdfOptions) | null | any |
| template | string | null | Template path |
| footerTemplate | string | null | Footer template path |
| headerTemplate | string | null | Header template path |
| styles | string[] | [] | Style paths |
| scripts | string[] | [] | Scripts paths |
| data | object | {} | Report data |## License
octopus-pdf is released under the MIT license.