docs_export_pdf
Generate PDF files from your documentation or built site. Specify the source path, output filename, and optionally include specific pages. Uses browser engines to produce accurate PDFs.
Instructions
Generate PDF from documentation using Puppeteer/Playwright
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| docsPath | Yes | Path to documentation or built site | |
| outputPath | Yes | Output path for PDF file | |
| includePages | No | Specific pages to include (optional, includes all by default) |
Implementation Reference
- src/tools/exportPdf.ts:7-70 (handler)The main handler function for docs_export_pdf tool. It extracts args (docsPath, outputPath, includePages) and returns a text response containing instructions for manually generating a PDF from documentation using Puppeteer/Playwright. It does NOT actually generate a PDF itself—it only provides a code snippet and instructions.
export async function exportPdf(args: any) { const { docsPath, outputPath, includePages } = args as ExportPdfArgs; const instructions = `📄 PDF Export Instructions: 1. Install dependencies: npm install --save-dev puppeteer 2. Create export script (pdf-export.js): \`\`\`javascript const puppeteer = require('puppeteer'); const path = require('path'); async function exportPdf() { const browser = await puppeteer.launch(); const page = await browser.newPage(); // Navigate to your built documentation await page.goto('file://${docsPath}/index.html', { waitUntil: 'networkidle0' }); // Generate PDF await page.pdf({ path: '${outputPath}', format: 'A4', printBackground: true, margin: { top: '20mm', right: '20mm', bottom: '20mm', left: '20mm' } }); await browser.close(); console.log('PDF generated: ${outputPath}'); } exportPdf(); \`\`\` 3. Run the script: node pdf-export.js Alternative tools: - prince (commercial, excellent quality) - wkhtmltopdf (free, good quality) - md-to-pdf (for simple Markdown) For Docusaurus, check: - docusaurus-prince-pdf - docusaurus-pdf`; return { content: [ { type: "text", text: instructions, }, ], }; } - src/tools/exportPdf.ts:1-5 (schema)TypeScript interface defining the input arguments for the exportPdf handler: docsPath (required), outputPath (required), and optional includePages array.
interface ExportPdfArgs { docsPath: string; outputPath: string; includePages?: string[]; } - src/index.ts:156-178 (registration)Tool registration object in the 'tools' array, defining name, description, and JSON Schema input validation for docs_export_pdf.
{ name: "docs_export_pdf", description: "Generate PDF from documentation using Puppeteer/Playwright", inputSchema: { type: "object", properties: { docsPath: { type: "string", description: "Path to documentation or built site", }, outputPath: { type: "string", description: "Output path for PDF file", }, includePages: { type: "array", items: { type: "string" }, description: "Specific pages to include (optional, includes all by default)", }, }, required: ["docsPath", "outputPath"], }, }, - src/index.ts:310-311 (registration)Route in the CallToolRequestSchema switch statement that dispatches 'docs_export_pdf' requests to the exportPdf handler function.
case "docs_export_pdf": return await exportPdf(args); - src/index.ts:15-15 (registration)Import statement that brings the exportPdf function from src/tools/exportPdf.ts into the main server file.
import { exportPdf } from "./tools/exportPdf.js";