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

Merge branch 'style_option' into 'main'

Add style option

See merge request !35
parents cb3ad598 dff9000e
No related branches found
No related tags found
1 merge request!35Add style option
Pipeline #35901 passed with stages
in 1 minute and 37 seconds
...@@ -17,44 +17,32 @@ pagedjs-cli ./path/to/index.html -o result.pdf ...@@ -17,44 +17,32 @@ pagedjs-cli ./path/to/index.html -o result.pdf
## Options ## Options
``` ```
-V, --version output the version number -i, --inputs [inputs] Inputs
-i, --inputs [inputs] Inputs -o, --output [output] Output
-o, --output [output] Output -d, --debug Debug
-d, --debug Debug -l, --landscape Landscape printing (default: false)
-l, --landscape Landscape printing (default: false) -s, --page-size [size] Print to Page Size [size]
-s, --page-size [size] Print to Page Size [size] -w, --width [size] Print to Page Width [width] in MM
-w, --width [size] Print to Page Width [width] in MM -h --height [size] Print to Page Height [weight] in MM
-h --height [size] Print to Page Height [weight] in MM --forceTransparentBackground Print with transparent background
--forceTransparentBackground Print with transparent background -t, --timeout [ms] Set a max timeout of [ms]
-t, --timeout [ms] Set a max timeout of [ms] -x, --html output html file
-x, --html output html file -b, --blockLocal Disallow access to filesystem for local files
-b, --blockLocal Disallow access to filesystem for local files -r, --blockRemote Disallow requests to remote servers
-r, --blockRemote Disallow requests to remote servers --allowedPath [allowedPaths] Only allow access to given filesystem paths, repeatable. (default: [])
--allowedPath [allowedPaths] Only allow access to given filesystem paths, repeatable. (default: []) --allowedDomain [allowedDomains] Only allow access to given remote domains, repeatable (default: [])
--allowedDomain [allowedDomains] Only allow access to given remote domains, repeatable (default: []) --outline-tags [tags] Specifies that an outline should be generated for the resulting PDF document. [tags] specifies
--outline-tags [tags] Specifies that an outline should be generated for the resulting PDF which HTML tags should be considered for that outline. "h1,h2" will trigger an outline with "h1"
document. [tags] specifies which HTML tags should be considered for that tags as root elements and "h2" elements as their childs.
outline. "h1,h2" will trigger an outline with "h1" tags as root elements --additional-script <script> Additional script tags which are added to the HTML document before rendering. This is useful for
and "h2" elements as their childs. adding custom pagedjs handlers. The option can be repeated. (default: [])
--additional-script <script> Additional script tags which are added to the HTML document before --browserEndpoint <browserEndpoint> Use a remote Chrome server with browserWSEndpoint
rendering. This is useful for adding custom pagedjs handlers. The option --browserArgs <browserArgs> Launch Chrome with comma separated args
can be repeated. (default: []) --media [media] Emulate "print" or "screen" media, defaults to print.
--browserEndpoint Use a remote Chrome server with browserWSEndpoint --style <script> Path to CSS stylesheets to be added before rendering (default: [])
--browserArgs <browserArgs> Additional comma separated flags for browser --help display help for command
``` ```
## Hyphenation
HTML can be pre-processed with soft hyphens by the [Hypher](https://github.com/bramstein/hypher) library.
Pass the abbreviation a language code (such as `en-us` or `de`) when calling the renderer. You can install languages beyond those included the package.json using npm.
```
pagedjs-cli ./path/to/index.html --hyphenate en-us --output
```
## Development ## Development
Link and build the JS Link and build the JS
``` ```
......
...@@ -42,6 +42,7 @@ program ...@@ -42,6 +42,7 @@ program
.option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint") .option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint")
.option("--browserArgs <browserArgs>", "Launch Chrome with comma separated args", commaSeparatedList) .option("--browserArgs <browserArgs>", "Launch Chrome with comma separated args", commaSeparatedList)
.option("--media [media]", "Emulate \"print\" or \"screen\" media, defaults to print.") .option("--media [media]", "Emulate \"print\" or \"screen\" media, defaults to print.")
.option("--style <script>", "Path to CSS stylesheets to be added before rendering", collect, [])
.parse(process.argv); .parse(process.argv);
...@@ -115,6 +116,7 @@ if (typeof input === "string") { ...@@ -115,6 +116,7 @@ if (typeof input === "string") {
allowedPaths: options.allowedPaths, allowedPaths: options.allowedPaths,
allowedDomains: options.allowedDomains, allowedDomains: options.allowedDomains,
additionalScripts: options.additionalScript, additionalScripts: options.additionalScript,
styles: options.style,
browserEndpoint: options.browserEndpoint, browserEndpoint: options.browserEndpoint,
timeout: options.timeout, timeout: options.timeout,
browserArgs: options.browserArgs, browserArgs: options.browserArgs,
......
...@@ -31,6 +31,7 @@ class Printer extends EventEmitter { ...@@ -31,6 +31,7 @@ class Printer extends EventEmitter {
this.timeout = options.timeout || 0; this.timeout = options.timeout || 0;
this.closeAfter = typeof options.closeAfter !== "undefined" ? options.closeAfter : true; this.closeAfter = typeof options.closeAfter !== "undefined" ? options.closeAfter : true;
this.emulateMedia = options.emulateMedia || "print"; this.emulateMedia = options.emulateMedia || "print";
this.styles = options.styles;
this.pages = []; this.pages = [];
} }
...@@ -156,6 +157,12 @@ class Printer extends EventEmitter { ...@@ -156,6 +157,12 @@ class Printer extends EventEmitter {
window.PagedConfig.auto = false; window.PagedConfig.auto = false;
}); });
for (const style of this.styles) {
await page.addStyleTag({
path: style
});
}
await page.addScriptTag({ await page.addScriptTag({
path: scriptPath path: scriptPath
}); });
......
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