Skip to content

mehrdadmms/jsreport-multipage-export

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsreport-multipage-export

You can export multiple HTMLs to a single PDF
This code is based on jsreport-core
You can see their documentation to understand how to design your HTML and pass parameters

Port

Server is running on port 8010 you can change it in config

Quit start

Install packages

npm install

Start server

node app.js

Quick example

    const fs = require('fs');
    const request = require('request');

    const body = [
        {
            "html": "content of ParamPage.html",
            "data": {
                "param":{
                    "followers":"12,342",
                    "taged":"200",
                    "engagementRate":"20.32%",
                    "posts":"2420"
                }
            }
        },
        {
            "html": "content of ParamPage.html",
            "data": {
                "param":{
                    "followers":"12,342",
                    "taged":"200",
                    "engagementRate":"20.32%",
                    "posts":"2420"
                }
            }
        }
    ]
    request.post("http://localhost:8010", {json: body}, (error, response, body) => {
        if (error) throw error;
        if (body.status !== 200) throw body;
        const filePath = './my_awesome_pdf.pdf';
        fs.writeFileSync(filePath, Buffer.from(body.data.pdf.data));
        console.log(filePath);
    });

Docker

For build docker:

docker build -t jsreport-multipage-export .

and for Run use:

docker run --init --cap-add=SYS_ADMIN --name NAME_CONTAINER -p 8010:8010 -d jsreport-multipage-export