auto-report

1.0.2 • Public • Published

Logo AutoReport


This repository contains the AutoReport source code.
AutoReport is a library to generate personalized PDF and XLS reports.

Table of contents

Installation

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.

License

MIT

Package Sidebar

Install

npm i auto-report

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

28.8 kB

Total Files

13

Last publish

Collaborators

  • lucianojsjr