npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docusaurus-wkhtmltopdf

v1.1.4

Published

Extract rendered data from Docusaurus and generate PDF, the hard way

Downloads

48

Readme

Docusaurus PDF Generator Using WKHTMLTOPDF

npm version

Extract rendered data from Docusaurus and generate PDF, the hard way. Please note that Wkhtmltopdf and Ghostscript must be installed and reachable in your PATH variable for this software to work. However, Ghostscript is optional and is only required if you wish to compress the generated PDF files.

Command Help

This project offers the following options and flags:

Options:
      --version           Show version number                          [boolean]
  -u, --url               Base URL, should be the baseUrl of the Docusaurus inst
                          ance (e.g. https://docusaurus.io/docs/)       [string]
  -s, --selector          CSS selector to find the link of the next page[string]
  -d, --dest              Working directory. Default to ./pdf           [string]
  -f, --file              Change default list output filename           [string]
  -o, --output            Change PDF output filename                    [string]
      --include-index     Include / (passed URL) in generated PDF
      --prepend           Prepend additional pages, split with comma    [string]
      --append            Append additional pages, split with comma     [string]
      --wkhtmltopdf-args  Additional options for wkhtmltopdf            [string]
      --list-only         Fetch list without generating PDF
      --pdf-only          Generate PDF without fetching list. Ensure list exists
      --toc               Generate the PDF with a table of contents
      --compress          Compress the output file. REQUIRES ghostscript!
      --stdout            Stream PDF to stdout
      --quiet             silence console output.
  -h, --help              Show help                                    [boolean]

Standard Usage

Before getting started, install Wkhtmltopdf. Ghostscript is optional. If you prefer to skip installation of node, wkhtmltopdf and ghostscript on your machine see Docker Usage below.

Here are a few examples of this software in action. Run the following commands to generate your PDFs:

# Genrate PDF from specific site under `docs` scope
npx docusaurus-wkhtmltopdf -u https://docusaurus.io/docs

# Example with more flags: create table of contents, compress the file, and pipe to stdout
npx docusaurus-wkhtmltopdf -u https://docusaurus.io/docs --compress --toc --stdout > documentation.pdf

To generate PDF from a local Docusaurus instance. You need to first build the site locally:

# Build the site
yarn build

# Serve built site locally
yarn serve

# Generate PDF from local Docusaurus instance
npx docusaurus-wkhtmltopdf -u http://localhost:4000/docs # Change port to your serving port

Docker Usage

The docker image comes with a working environment so no other external software is needed. Here are a few examples of this software in action. Run the following commands to generate your desired PDF:

# Generate PDF from specific site under `docs` scope. Please note that the folder with the generated file can be found in /tmp/pdf
docker run --rm -v /tmp/pdf:/d2p/pdf nuxnik/docusaurus-to-pdf -u https://docusaurus.io/docs

# Let's use some more flags: create table of contents, compress the file, and pipe from stdout to documentation.pdf
docker run --rm nuxnik/docusaurus-to-pdf -u https://docusaurus.io/docs --toc --compress --stdout > documentation.pdf

Modifications

Like mr-pdf, this package looks for the next pagination links on generated Docusaurus site. Collect them in a list and then pass the list to wkhtmltopdf to generate the PDF. You can specify the CSS selector if you're using a custom Docusaurus theme:

npx docusaurus-wkhtmltopdf -u https://docusaurus.io/docs --selector 'nav.custom-pagination-item--next > a'

You can also customize the CSS of the pages which are scraped by the crawler by modifying "print.css" file located in the project root. This CSS file is applied to the pages before being processed through Wkhtmltopdf. Depending on how this file is modified, will change the overall look of the generated PDF file.