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

Add style option

parent cb3ad598
Branches style_option
No related tags found
1 merge request!35Add style option
Pipeline #35900 passed with stages
in 2 minutes and 19 seconds
......@@ -17,44 +17,32 @@ pagedjs-cli ./path/to/index.html -o result.pdf
## Options
```
-V, --version output the version number
-i, --inputs [inputs] Inputs
-o, --output [output] Output
-d, --debug Debug
-l, --landscape Landscape printing (default: false)
-s, --page-size [size] Print to Page Size [size]
-w, --width [size] Print to Page Width [width] in MM
-h --height [size] Print to Page Height [weight] in MM
--forceTransparentBackground Print with transparent background
-t, --timeout [ms] Set a max timeout of [ms]
-x, --html output html file
-b, --blockLocal Disallow access to filesystem for local files
-r, --blockRemote Disallow requests to remote servers
--allowedPath [allowedPaths] Only allow access to given filesystem paths, 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 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: [])
--browserEndpoint Use a remote Chrome server with browserWSEndpoint
--browserArgs <browserArgs> Additional comma separated flags for browser
-i, --inputs [inputs] Inputs
-o, --output [output] Output
-d, --debug Debug
-l, --landscape Landscape printing (default: false)
-s, --page-size [size] Print to Page Size [size]
-w, --width [size] Print to Page Width [width] in MM
-h --height [size] Print to Page Height [weight] in MM
--forceTransparentBackground Print with transparent background
-t, --timeout [ms] Set a max timeout of [ms]
-x, --html output html file
-b, --blockLocal Disallow access to filesystem for local files
-r, --blockRemote Disallow requests to remote servers
--allowedPath [allowedPaths] Only allow access to given filesystem paths, 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
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: [])
--browserEndpoint <browserEndpoint> Use a remote Chrome server with browserWSEndpoint
--browserArgs <browserArgs> Launch Chrome with comma separated args
--media [media] Emulate "print" or "screen" media, defaults to print.
--style <script> Path to CSS stylesheets to be added before rendering (default: [])
--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
Link and build the JS
```
......
......@@ -42,6 +42,7 @@ program
.option("--browserEndpoint <browserEndpoint>", "Use a remote Chrome server with browserWSEndpoint")
.option("--browserArgs <browserArgs>", "Launch Chrome with comma separated args", commaSeparatedList)
.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);
......@@ -115,6 +116,7 @@ if (typeof input === "string") {
allowedPaths: options.allowedPaths,
allowedDomains: options.allowedDomains,
additionalScripts: options.additionalScript,
styles: options.style,
browserEndpoint: options.browserEndpoint,
timeout: options.timeout,
browserArgs: options.browserArgs,
......
......@@ -31,6 +31,7 @@ class Printer extends EventEmitter {
this.timeout = options.timeout || 0;
this.closeAfter = typeof options.closeAfter !== "undefined" ? options.closeAfter : true;
this.emulateMedia = options.emulateMedia || "print";
this.styles = options.styles;
this.pages = [];
}
......@@ -156,6 +157,12 @@ class Printer extends EventEmitter {
window.PagedConfig.auto = false;
});
for (const style of this.styles) {
await page.addStyleTag({
path: style
});
}
await page.addScriptTag({
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