Created
October 14, 2020 16:46
-
-
Save pablonarvaez20152016/2a6fa4755a07a0fb5ceb318fe5969ea0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var pdf = await Myfunction.getPDF( | |
fs.readFileSync('/recipePDF.html', 'utf8').toString(), | |
{ | |
data: info | |
}, | |
fs.readFileSync('/helpers.js', 'utf8').toString(), | |
'', | |
'' | |
) | |
res.contentType('application/pdf'); | |
res.header('Content-Disposition": "filename=reportBIG.pdf"'); | |
res.status(200); | |
pdf.pipe(res); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extensions": { | |
"authentication": { | |
"cookieSession": { | |
"secret": "000000" | |
}, | |
"admin": { | |
"username": "admin", | |
"password": "0000" | |
}, | |
"enabled": true | |
}, | |
"scripts": { | |
"timeout": 9400000, | |
"strategy": "http-server" | |
}, | |
"express":{ | |
"inputRequestLimit":"5000mb", | |
"renderTimeout":9400000 | |
}, | |
"phantom-pdf":{ | |
"timeout":9400000 | |
}, | |
"xlsx":{ | |
"escapeAmp":true, | |
"numberOfParsedAddIterations":50, | |
"addBufferSize":50000000 | |
}, | |
"sample-template": { | |
"createSamples": true | |
} | |
}, | |
"httpPort": 5488, | |
"store": { | |
"provider": "memory" | |
}, | |
"blobStorage": { | |
"provider": "memory" | |
}, | |
"logger": { | |
"console": { | |
"transport": "console", | |
"level": "debug" | |
}, | |
"file": { | |
"transport": "file", | |
"level": "info", | |
"filename": "logs/reporter.log" | |
}, | |
"error": { | |
"transport": "file", | |
"level": "error", | |
"filename": "logs/error.log" | |
} | |
}, | |
"allowLocalFilesAccess": true, | |
"templatingEngines": { | |
"timeout":9400000, | |
"strategy": "http-server" | |
}, | |
"chrome": { | |
"timeout": 9400000 | |
}, | |
"Phantom": { | |
"timeout": 9400000 | |
}, | |
"reportTimeout":960000 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getPDF = async (template, data, helpers = '', header = '', footer = '') => { | |
try { | |
return client.render({ | |
template: { | |
content: template, | |
recipe: 'phantom-pdf', | |
engine: 'handlebars', | |
helpers: helpers, | |
phantom: { | |
header: header, | |
footer: footer, | |
format: 'Letter', | |
orientation: 'portrait', | |
headerHeight: "2.5 cm", | |
footerHeight: "1 cm", | |
margin: { | |
"top": "1 cm", | |
"left": "0.5 cm", | |
"right": "0.5 cm", | |
"bottom": "1 cm" | |
},timeout: 9480000 | |
} | |
}, | |
data: data, | |
options: { | |
reports: { | |
"save": true | |
} | |
}, | |
}); | |
} catch (error) {return error;} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment