Skip to content

Conversation

@aloisklink
Copy link
Collaborator

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 --format and --margin field to specify the formatting of the PDF file, and adds tests to make sure we don't break anything, and resolves #18.

The --margin command 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:

npx docusaurus-pdf "https://v2.docusaurus.io/docs/2.0.0-alpha.56/lifecycle-apis" --margin '1cm 2cm 1cm 2cm'

Additionally, I've made --no-sandbox a global option, so it works on all commands, including the default docusaurus command.

@aloisklink aloisklink added the enhancement New feature or request label Jul 5, 2020
@kohheepeace kohheepeace self-requested a review July 6, 2020 14:37
@maxarndt maxarndt self-requested a review July 7, 2020 06:31
@aloisklink aloisklink marked this pull request as ready for review July 7, 2020 08:59
@aloisklink aloisklink marked this pull request as draft July 7, 2020 09:00
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.
@aloisklink aloisklink force-pushed the add-puppeteer-opts branch from 6652068 to 04cdcf1 Compare July 7, 2020 09:05
@aloisklink aloisklink marked this pull request as ready for review July 7, 2020 09:09
@aloisklink
Copy link
Collaborator Author

Sorry for marking this ready-to-review, then draft, then ready-to-review again, I had to do some git cherry-pick because I squashed-and-merge the other pull request.

Copy link
Owner

@kohheepeace kohheepeace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aloisklink super nice 💯 thanks!! 👍

Copy link
Collaborator

@maxarndt maxarndt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

@aloisklink aloisklink Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙃

Copy link
Collaborator Author

@aloisklink aloisklink Jul 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aloisklink! Any progress on this? Let me know if I can help you bringing this PR into production!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to add margin around PDF

3 participants