rspress-plugin-pdf-generator

April 16, 2026 · View on GitHub

Preview

简体中文

Generate PDF files from your Rspress site during rspress build.

Features

  • Generate a single merged PDF or one PDF per page.
  • Build table of contents for the entire site.
  • Preserve clickable links inside the merged PDF, including page-level TOC links.
  • Generate PDF document outlines using page titles and headings.
  • Support multi-language output, selective languages, and merged multi-language PDFs.

Installation

pnpm add rspress-plugin-pdf-generator

This plugin uses Playwright to render PDFs. If Chromium is not installed locally, run:

pnpm exec playwright install chromium

Usage

import * as path from 'node:path'
import { defineConfig } from '@rspress/core'
import pdfGenerator from 'rspress-plugin-pdf-generator'

export default defineConfig({
  root: path.join(__dirname, 'docs'),
  title: 'My Docs',
  logo: 'https://example.com/logo.svg',
  plugins: [
    pdfGenerator({
      mode: 'single',
      outputDir: 'pdf',
      fileName: 'site.pdf',
    }),
  ],
})

After rspress build, the generated PDF files will be written to:

  • doc_build/pdf/en-site.pdf in single mode by default
  • doc_build/pdf/<language>/... in multiple mode

Options

mode

  • Type: 'single' | 'multiple'
  • Default: 'single'

Controls whether the plugin outputs one merged PDF or one PDF per page.

outputDir

  • Type: string
  • Default: 'pdf'

Output directory relative to config.outDir. Absolute paths are also supported.

fileName

  • Type: string
  • Default: 'site.pdf'

Used in single mode as the merged PDF file name.

i18n

  • Type:
{
  enabled?: boolean
  languages?: string[]
  merge?: boolean
}

Controls multi-language PDF generation.

  • enabled: enable multi-language handling
  • languages: limit generation to specific languages
  • merge: merge all selected languages into a single PDF in single mode

Notes

  • The plugin generates PDFs from built HTML output, so it only runs during rspress build.
  • Page order follows resolved nav -> sidebar structure, then falls back to remaining routes.
  • The plugin reads the site logo from top-level UserConfig.logo.
  • This plugin uses Playwright to render PDFs. If you encounter issues with Chromium, ensure it's installed and compatible with your environment. You can also customize the PDF rendering options in src/pdf-utils.ts if needed.