auto-report
v1.0.2
Published
A wonderful Javascript library to make great reports.
Downloads
4
Maintainers
Readme
Table of contents
npm install auto-report --save
Import it to your code using:
const AutoReport = require("auto-report");
Examples
AutoReport
use HTML with tags to generate the PDF. For the examples below
We will use the following HTML.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<p>{{@report_name}}</p>
</div>
{{@table}}
</body>
</html>
Example 1) Render a value:
const template = '<html>...'; // Template defined above.
const AutoReport = require('auto-report');
const AutoReportPDF = new AutoReport.PDF();
AutoReportPDF.init(template);
AutoReportPDF.render('report_name', 'New Report Name');
AutoReportPDF.create('your-path/file.pdf').then(data => console.log(data)).catch(err => console.log(err));
Example 2) Render a table:
const template = '<html>...'; // Template defined above.
const AutoReport = require('auto-report');
const AutoReportPDF = new AutoReport.PDF();
const columns = [{
name: 'Name'
}, {
name: 'Age'
}, {
name: 'Country'
}];
const rows = [
['Mário', 12, 'BR'],
['Martin', 23, 'US'],
['Jacque', 22, 'FR']
];
AutoReportPDF.init(template);
AutoReportPDF.renderTable(columns, rows, {
tag: 'table' //The tag that should be replaced.
});
AutoReportPDF.create('your-path/file.pdf').then(data => console.log(data)).catch(err => console.log(err));
or (the rows can be an array of objects):
const columns = [{
name: 'Name'
}, {
name: 'Age'
}, {
name: 'Country'
}];
const rows = [{
name: 'Mário',
user_age: 12,
country: 'BR'
}, {
name: 'Martin',
user_age: 23,
country: 'US'
}, {
name: 'Jacque',
user_age: 22,
country: 'FR'
}];
AutoReportPDF.init(template);
AutoReportPDF.renderTable(columns, rows, {
tag: 'table', //The tag that should be replaced.,
properties: ['name', 'user_age', 'country'] //Properties to access row object
});
AutoReportPDF.create('your-path/file.pdf').then(data => console.log(data)).catch(err => console.log(err));
More examples
Other examples will be created soon in addition to the complete documentation.
Contributing
You may contribute in several ways like creating new features, fixing bugs, improving documentation and examples or translating any document here to your language.