Convert Docusaurus documentation sites to high-quality PDF with full MDX support.
- Full MDX Support - Parses all Docusaurus components including DocCardList, Details, Admonitions, Tabs
- LaTeX-based PDF Generation - Uses LaTeX (
latexmkby default) for professional-quality PDF output with proper typography - Multilingual & i18n - Automatically reads translations from
i18n/directory and merges with fallbacks - Line Highlighting - Supports code block metadata
{1,3-5}and comments (e.g.// highlight-next-line) usingfvextra - Math Equations - Supports inline
$...$and block$$...$$LaTeX math equations - Mermaid & PlantUML - Automatically generates high-quality diagrams with source code fallbacks if skipped or failed
- Lettered Lists - Natively compiles
a. b. c.lists usingenumitem - Emoji Rendering - LuaLaTeX renders emojis using Twemoji Mozilla font
- Section Filtering - Generate PDFs for specific sidebar sections only
- Docker-based LaTeX - No local LaTeX installation required
- Multiple Output Modes - Per-language, per-section, or single PDF
# Install globally from GitHub (no token required)
npm install -g github:BluPix/docusaurus2pdf
# Generate PDF from your Docusaurus site
docusaurus2pdf -i ./my-docusaurus-site -o ./pdf-outputYou can install the package directly from this repository. No GitHub token is required, and the package will automatically build during installation.
npm install -g github:BluPix/docusaurus2pdfThis package is also published to the GitHub Packages registry. Before installing, configure your npm client to use the GitHub registry for the @blupix scope.
Create or edit your ~/.npmrc file (or a local .npmrc in your project) and add:
@blupix:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PERSONAL_ACCESS_TOKEN
(Ensure your GitHub token has the read:packages permission.)
Then, install the package:
npm install -g @blupix/docusaurus2pdfgit clone https://github.com/your-repo/docusaurus2pdf.git
cd docusaurus2pdf
npm install
npm run build| Option | Alias | Description | Default |
|---|---|---|---|
--input <path> |
-i |
Input Docusaurus site directory | (required) |
--output <path> |
-o |
Output directory for PDFs | ./pdf-export |
--engine <engine> |
-e |
LaTeX engine (lualatex, xelatex, pdflatex, tectonic) | lualatex |
--single |
-s |
Generate single PDF with all content | false |
--per-language |
-l |
Generate separate PDF per language | true |
--tex-only |
- | Generate .tex files only, skip PDF compilation | false |
--compile-only |
- | Compile existing .tex files to PDF | false |
--no-docker |
- | Use local TeX installation instead of Docker | false |
--sections <names> |
- | Comma-separated section names to generate | (all) |
--strip-numbering |
- | Strip manual numbering from headings (e.g., "3. Title" → "Title") | false |
--convert-emoji |
- | Convert emoji to text (e.g., "📷" → "[Camera]") for PDF output | false |
--suppress-caption-numbers |
- | Suppress automatic figure numbering in captions | false |
# Generate PDFs per language (default behavior)
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output
# Generate single PDF with all content
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output --single
# Use specific LaTeX engine
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output --engine xelatexThe tool automatically converts PlantUML and Mermaid diagrams to SVG format for high-quality PDF output:
- Mermaid: Server-side rendered using jsdom (no browser needed)
- PlantUML: Local generation via Java JAR (if available) or TeaVM PlantUML.js (pure JavaScript fallback)
Note: All diagrams are converted to SVG format. For LaTeX compilation, use lualatex or xelatex (recommended) as they have built-in SVG support via the svg package. The pdflatex engine is not supported for documents containing diagrams.
Both diagram types use LaTeX's \includesvg command and maintain vector quality in the output PDF. No additional configuration needed - diagrams are automatically detected and converted.
Generate PDFs only for specific sidebar sections:
# Single section
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output --sections "tutorials"
# Multiple sections
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output --sections "tutorials,guides,api"Available section names are derived from your Docusaurus sidebar configuration (autogenerated directories or explicit categories).
# Generate only .tex files (for custom processing)
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output --tex-only
# Compile existing .tex files to PDF
npx @blupix/docusaurus2pdf -i ./docs -o ./pdf-output --compile-onlyFor automatic PDF generation during your Docusaurus build, use the plugin:
// docusaurus.config.js
module.exports = {
// ... your config
plugins: [
[
'@blupix/docusaurus2pdf/plugin',
{
outputDir: './pdf-output',
single: false,
sections: ['tutorials', 'guides'],
},
],
],
};| Option | Type | Description | Default |
|---|---|---|---|
outputDir |
string |
Output directory for PDFs | ./pdf-export |
single |
boolean |
Generate single PDF | false |
sections |
string[] |
Sections to include | all |
texOnly |
boolean |
Generate only .tex files | false |
stripNumbering |
boolean |
Strip manual numbering from headings | false |
suppressCaptionNumbers |
boolean |
Suppress figure numbering in captions | false |
onSuccess |
function |
Callback after generation | - |
| Component | LaTeX Output |
|---|---|
DocCardList |
\begin{itemize} ... \end{itemize} |
DocCard |
Bold text with optional description |
Details |
tcolorbox with title |
Admonitions (:::tip, etc.) |
Colored tcolorbox with custom icons |
Tabs (<Tabs><TabItem>) |
Styled tcolorbox card per tab |
Math Equations ($...$, $$...$$) |
Inline math or display math blocks |
| Mermaid / PlantUML | PDF/EPS vector graphic (or source code fallback if skipped/failed) |
Code Blocks (title, showLineNumbers, highlights) |
Verbatim with highlightlines (via fvextra) or lstlisting (via listings) |
| Emojis (LuaLaTeX) | \emoji{name} with Twemoji font |
- Node.js 18+
- LaTeX with
lualatexorxelatex(for PDF compilation with SVG support) - Optional: Java + PlantUML (for better PlantUML diagram quality)
For PDF compilation with SVG diagram support, install a modern LaTeX distribution:
macOS:
brew install --cask mactexUbuntu/Debian:
sudo apt-get install texlive-fullMermaid diagrams work out of the box (server-side rendering via jsdom).
PlantUML diagrams have two options:
- Recommended: Install Java and PlantUML for best quality:
# macOS brew install plantuml # Ubuntu/Debian sudo apt-get install plantuml
- Fallback: Uses bundled TeaVM PlantUML.js (pure JavaScript, no Java needed, ~8MB)
import { Renderer, SiteLoader } from '@blupix/docusaurus2pdf';
const siteLoader = new SiteLoader();
const site = await siteLoader.load('./my-docusaurus-site');
const renderer = new Renderer({
OutputDir: './pdf-output',
Engine: 'lualatex',
Sections: ['tutorials', 'guides'],
});
// Generate single PDF
await renderer.renderSingle(site);
// Or per language
await renderer.renderPerLanguage(site);
// Or per section
await renderer.renderPerSection(site);If you see this error, either:
- Install Docker and ensure it's running
- Install a local LaTeX distribution and use
--no-docker
Ensure:
- PlantUML code blocks use triple backticks with
plantumllanguage - PlantUML server is accessible (uses public PlantUML server by default)
- Check the
.logfile in the output directory for LaTeX errors - Try
--tex-onlyto inspect the generated .tex file - Ensure enough memory is available for LaTeX compilation
This project was inspired by a school assignment at VŠPJ Jihlava (2007–2008), originally assigned by Tomáš Richta — a DokuWiki-to-LaTeX converter written in C. Years later, I used that original codebase as a starting point, feeding it into LLM-based tools. What began as a simple port evolved through Go and eventually into TypeScript, driven by the complexity of real-world Docusaurus projects. While this implementation shares no code with the original, the core idea carried through from the very beginning.
MIT