Skip to content
Snippets Groups Projects
Commit 2896e827 authored by Fred Chasen's avatar Fred Chasen
Browse files

Merge branch 'additional-scripts' into 'master'

Added argument for adding additional scripts to a document

See merge request tools/pagedjs-cli!7
parents ad88253a 8d051b1a
No related branches found
No related tags found
No related merge requests found
......@@ -17,22 +17,23 @@ pagedjs-cli ./path/to/index.html -o result.pdf
## Options
```
-h, --help output usage information
-V, --version output the version number
-i, --inputs [inputs] Inputs
-o, --output [output] Output
-d, --debug Show Electron Window to Debug
-l, --landscape Landscape printing
-s, --page-size [size] Print to Page Size [size]
-w, --width [size] Print to Page Width [width]
-h --height [size] Print to Page Height [weight]
-m, --page-margin [margin] Print with margin [margin]
-n, --hyphenate [lang] Hyphenate with language [language], defaults to "en-us"
-hi, --hypher_ignore [str] Ignore passed element selectors, such as ".class_to_ignore, h1"
-ho, --hypher_only [str] Only hyphenate passed elements selector, such as ".hyphenate, aside"
-e, --encoding [type] Set the encoding of the input html, defaults to "utf-8"
-t, --timeout [ms] Set a max timeout of [ms]
--outline-tags [tags] Specifies that an outline should be generated for the resulting PDF document. [tags] specifies which HTML tags should be considered for that outline. "h1,h2" will trigger an outline with "h1" tags as root elements and "h2" elements as their childs.
-h, --help output usage information
-V, --version output the version number
-i, --inputs [inputs] Inputs
-o, --output [output] Output
-d, --debug Show Electron Window to Debug
-l, --landscape Landscape printing
-s, --page-size [size] Print to Page Size [size]
-w, --width [size] Print to Page Width [width]
-h --height [size] Print to Page Height [weight]
-m, --page-margin [margin] Print with margin [margin]
-n, --hyphenate [lang] Hyphenate with language [language], defaults to "en-us"
-hi, --hypher_ignore [str] Ignore passed element selectors, such as ".class_to_ignore, h1"
-ho, --hypher_only [str] Only hyphenate passed elements selector, such as ".hyphenate, aside"
-e, --encoding [type] Set the encoding of the input html, defaults to "utf-8"
-t, --timeout [ms] Set a max timeout of [ms]
--outline-tags [tags] Specifies that an outline should be generated for the resulting PDF document. [tags] specifies which HTML tags should be considered for that outline. "h1,h2" will trigger an outline with "h1" tags as root elements and "h2" elements as their childs.
--additional-script <script> Additional script tags which are added to the HTML document before rendering. This is useful for adding custom pagedjs handlers. The option can be repeated. (default: [])
```
## Hyphenation
......
......@@ -31,8 +31,16 @@ program
"HTML tags should be considered for that outline. " +
"\"h1,h2\" will trigger an outline with \"h1\" tags as root elements " +
"and \"h2\" elements as their childs.")
.option("--additional-script <script>", "Additional script tags which are " +
"added to the HTML document before rendering. This is useful for " +
"adding custom pagedjs handlers. The option can be repeated.",
collect, [])
.parse(process.argv);
function collect(value, previous) {
return previous.concat(value);
}
let input = program.inputs || program.args[0];
......@@ -96,7 +104,7 @@ if (typeof input === "string") {
}
(async () => {
let printer = new Printer(headless, allowLocal);
let printer = new Printer(headless, allowLocal, program.additionalScript);
printer.on("page", (page) => {
if (page.position === 0) {
......
......@@ -14,11 +14,12 @@ let scriptPath = paths[0] + "node_modules" + paths[paths.length-1];
const PostProcesser = require("./postprocesser");
class Printer extends EventEmitter {
constructor(headless, allowLocal) {
constructor(headless, allowLocal, additionalScripts) {
super();
this.headless = headless !== false;
this.allowLocal = allowLocal;
this.pages = [];
this.additionalScripts = additionalScripts;
}
async setup() {
......@@ -98,6 +99,12 @@ class Printer extends EventEmitter {
path: scriptPath
});
for (const script of this.additionalScripts) {
await page.addScriptTag({
path: script
});
}
// await page.exposeFunction("PuppeteerLogger", (msg) => {
// console.log(msg);
// });
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment