Let my HOME alone 1/2
This commit is contained in:
parent
2ae37e902e
commit
a83e45df5e
94 changed files with 328 additions and 58 deletions
56
config/scripts/html2pdf
Executable file
56
config/scripts/html2pdf
Executable file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
// Imports
|
||||
var fs = require('fs');
|
||||
var pdf = require('html-pdf');
|
||||
var yargs = require('yargs');
|
||||
|
||||
|
||||
// Understanding
|
||||
var argv = yargs
|
||||
.usage("Usage: $0 -o out.pdf [options]")
|
||||
.example('$0 -i doc.pdf -o doc.pdf', 'Convert doc.html to PDF using the default values')
|
||||
.help('h')
|
||||
.alias('h', 'help')
|
||||
|
||||
.describe('i', 'Input file')
|
||||
.alias('i', 'input')
|
||||
.default('i', '/dev/stdin')
|
||||
|
||||
.describe('o', 'Output file')
|
||||
.alias('o', 'output')
|
||||
|
||||
.describe('t', 'Title of file')
|
||||
.alias('t', 'title')
|
||||
.default('t', 'Sans titre')
|
||||
|
||||
.describe('b', 'Border')
|
||||
.alias('b', 'border')
|
||||
.default('b', '2cm')
|
||||
|
||||
.demandOption(['o'])
|
||||
.argv;
|
||||
|
||||
|
||||
// Settings
|
||||
options = {
|
||||
"base": "file://" + process.cwd() + '/',
|
||||
"format": "A4",
|
||||
"orientation": "portrait",
|
||||
"border": argv.border,
|
||||
|
||||
"footer": {
|
||||
"height": "10mm",
|
||||
"contents": {
|
||||
default: '<div style="text-align: left; float: left;">' + argv.title + '</div> <div style="text-align:right; float: right;">{{page}}/{{pages}}</div>',
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// Reading
|
||||
htmlString = fs.readFileSync(argv.i, "utf8");
|
||||
|
||||
// Conversion
|
||||
pdf.create(htmlString, options).toFile(argv.o, function(err, res) {
|
||||
if (err) console.error(err);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue