Add option to pick PDF margins and format (A4/A3/etc.)#20
Add option to pick PDF margins and format (A4/A3/etc.)#20aloisklink wants to merge 2 commits intokohheepeace:masterfrom
Conversation
puppeteer, commander, and chalk all went up a MAJOR version, but the main breaking change was updating to Node v10, which we need anyway.
Adds the --format and --margin field to specify the formatting of the PDF file, and adds tests to make sure we don't break anything. Additionally, allows setting --no-sandbox on all commands, including the default docusaurus command. Fixes kohheepeace#18.
6652068 to
04cdcf1
Compare
|
Sorry for marking this ready-to-review, then draft, then ready-to-review again, I had to do some |
kohheepeace
left a comment
There was a problem hiding this comment.
@aloisklink super nice 💯 thanks!! 👍
maxarndt
left a comment
There was a problem hiding this comment.
Hey @aloisklink!
I'm late again with my answer, but I took the time to try the changes.
Let me know if anything is unclear for you!
I'm looking forward seeing those new features in the new release 😎
| console.log(chalk.green("Finish generating PDF!")); | ||
| }); | ||
|
|
||
| program |
There was a problem hiding this comment.
Is there a way to show the new options --margin and --format for the other commands as well?
If I run one of the following I don't see those options listed:
node bin/index.js from-website --help
node bin/index.js from-build --help
node bin/index.js from-build-config --help
I think it would be helpful to see the options on every command which supports them.
There was a problem hiding this comment.
Good catch!
I think they currently only show up when you run node bin/index.js --help, since they're global options for all commands.
I'll see if I can add a message saying something like:
$ node bin/index.js from-website --help
Usage: docusaurus-pdf from-website [options] <initialDocsUrl> [filename]
Generate PDF from an already hosted website
Global options can be seen by running `docusaurus-pdf --help`
Options:
-h, --help display help for command| - Mandatory: `dirPath` which points to the build directory created with `docusaurus build`. | ||
| - Mandatory: `firstDocPagePath` is the URL path segment (without `baseUrl`) of your first docs page you whish to have included in the PDF. | ||
| - Optional: If you have a `baseUrl` configured in your `docusaurus.config.js` then pass this value as `baseUrl`. | ||
| - Optional: You can specify larger/smaller margins, e.g. `--margin "1cm 1.5cm 1cm 2cm"` (order top right bottom left, like the css margin field). |
There was a problem hiding this comment.
I tried this but unfortunately this doesn't work for me:
~/Dow/tm/docusaurus-pdf/t/test-website add-puppeteer-opts !1 node ../../bin/index.js from-build-config --margin "1cm 1.5cm 1cm 2cm"
Error: Was expecting exactly 4 margin specifiers, instead got 5. Margin specifier was "1cm 1.5cm 1cm 2cm".
There seems to be a bug if a decimal number is used 🙃
There was a problem hiding this comment.
Good catch! I didn't even think of people using 1.5 cm, even though it's something I always do with LaTeX. I think I'll probably use a library like https://github.com/jedmao/parse-css-sides, since there seems to be quite a lot of edge cases, instead of rolling my own parser.
There was a problem hiding this comment.
Hey @aloisklink! Any progress on this? Let me know if I can help you bringing this PR into production!
Note: Leaving this as a draft pull request until the style changes in #19 has been merged, since currently, the changes are mixed up with the style changes.
Adds the
--formatand--marginfield to specify the formatting of the PDF file, and adds tests to make sure we don't break anything, and resolves #18.The
--margincommand accepts a string specifier for top, right, bottom, left like the CSS Margin field.For example, the following will pass
margin: {top: "1cm", right: "2cm", bottom: "1cm", left: "2cm"}to puppeteer:Additionally, I've made
--no-sandboxa global option, so it works on all commands, including the default docusaurus command.