kohheepeace / docusaurus-pdf

Generate PDF for docusaurus
https://drive.google.com/file/d/19P3qSwLLUHYigrxH3QXIMXmRpTFi4pKB/view
113 stars 18 forks source link

npm version code style: prettier Github Action: Test

⚠️ Caution!

Currently, this package is not catching up with docusaurus v2 and not actively developed, it is under MIT license, so feel free to fork and modify it.

Introduction

This is a PDF generator from docusaurus document.

*Note

Demo

This is generated PDF of official docusaurus website: https://drive.google.com/file/d/19P3qSwLLUHYigrxH3QXIMXmRpTFi4pKB/view

Usage

Use with already hosted docusaurus instance (locally or somewhere in the net)

npx docusaurus-pdf <initialDocsUrl> [filename]

For example

npx docusaurus-pdf http://localhost:3000/myBaseUrl/docs/doc1 hoge.pdf

*NOTE!

Use with the build artifact of docusaurus build

npx docusaurus-pdf from-build [options] <dirPath> <firstDocPagePath> [baseUrl]

For example

npx docusaurus-pdf from-build build/ docs/doc1 /myBaseUrl/

You can also try to automatically load the firstDocPagePath and baseUrl from docusaurus.config.js:

npx docusaurus-pdf from-build-config

Parameters

Docker usage

All dependencies needed to create a PDF from your docusaurus site are bundled in our Dockerfile.

Create PDF from build artifact

Run docusaurus-pdf with prebuild image

docker run --rm -it -v /someDir/my-docusaurus:/workspace maxys/docusaurus-pdf:latest from-build --no-sandbox -o /workspace/build/docs.pdf /workspace/build docs/doc1 myBaseUrl

Build Docker image locally

You can create the image locally without pulling maxys/docusaurus-pdf:latest from the Docker Hub with:

docker build -t "docusaurus-pdf" .

Link of PDF

  1. Move generated pdf file to static/img folder.
  2. <a> tag with target="_blank"
    <a href={useBaseUrl('img/docusaurus.pdf')} target="_blank">
    Download PDF
    </a>

NOTE!

  1. If this plugin cannot find next page link, PDF generation will stop.

note

  1. Dark theme PDF cannot be generated correctly now.