Sponsored by Deepsite.site

PDF Generator MCP Server

Created By
FabianGenell7 months ago
Content

PDF Generator MCP Server

A powerful MCP (Model Context Protocol) server for generating professional PDFs from markdown content with custom styling, image support, and various formatting options.

Features

  • 🎨 Multiple Built-in Themes: Default, Professional, Minimal, and Dark themes
  • 📸 Smart Image Handling: Automatic optimization, caching, and embedding
  • 📄 Advanced PDF Options: Headers, footers, page numbers, TOC generation
  • 🎯 Template System: Create and reuse custom templates
  • Markdown Validation: Check content before generation
  • 🚀 Performance Optimized: Browser instance reuse, image caching
  • 💼 Custom Styles: Save and reuse custom PDF styles with prompts and formatting

Installation

No installation required! Add directly to your Claude desktop configuration:

{
  "mcpServers": {
    "pdf-generator": {
      "command": "npx",
      "args": ["github:FabianGenell/pdf-mcp-server"]
    }
  }
}

That's it! The server will be downloaded and run automatically.

Alternative: Local Development

# Clone the repository
git clone https://github.com/FabianGenell/pdf-mcp-server
cd pdf-mcp-server
npm install

# Add to Claude desktop configuration
{
  "mcpServers": {
    "pdf-generator": {
      "command": "node",
      "args": ["/path/to/pdf-mcp-server/src/index.js"]
    }
  }
}

Available Tools

1. generate_pdf

Generate a PDF from markdown content. PDFs are saved to your Downloads folder by default.

await generate_pdf({
  content: "# My Document\n\nThis is **markdown** content.",
  output_path: "output.pdf",  // Saves to ~/Downloads/output.pdf
  options: {
    theme: "professional",
    include_toc: true,
    page_numbers: true
  }
});

Note: If you provide just a filename or relative path, the PDF will be saved to your Downloads folder. Use an absolute path to save elsewhere.

2. embed_images

Process and embed images in markdown with optimization. Supports local paths, URLs, and base64 data URLs.

Image Source Types

Local Files (from your computer):

await embed_images({
  markdown_content: "# Report\n\n[IMAGE_1]\n\nSome text here.",
  image_sources: [{
    placeholder: "[IMAGE_1]",
    source: "/Users/username/Pictures/screenshot.png",  // Absolute path
    caption: "Application Screenshot",
    alignment: "center"
  }]
});

Remote URLs:

await embed_images({
  markdown_content: "# Report\n\n[LOGO]\n\nCompany overview.",
  image_sources: [{
    placeholder: "[LOGO]",
    source: "https://example.com/images/logo.png",  // Remote URL
    caption: "Company Logo",
    alignment: "center"
  }]
});

Base64 Data URLs:

await embed_images({
  markdown_content: "# Report\n\n[CHART]\n\nData analysis.",
  image_sources: [{
    placeholder: "[CHART]",
    source: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==",  // Base64 data URL
    caption: "Generated Chart",
    alignment: "center"
  }]
});

AI Agent Guidelines

For AI agents, you can provide images in three ways:

  1. Local Computer Paths: Use absolute paths like /Users/username/Documents/image.png or C:\Users\username\Documents\image.png
  2. Online Images: Use direct URLs like https://example.com/image.png
  3. Generated/Uploaded Images: Use base64 data URLs starting with data:image/[type];base64,[data]

All image types are automatically optimized, cached, and sized appropriately for PDF performance. Images are automatically limited to 70% of page height to ensure proper layout.

3. create_styled_template

Create reusable templates for consistent styling.

await create_styled_template({
  template_name: "company-report",
  css_content: "/* Custom CSS */",
  html_template: "<!-- Optional HTML structure -->"
});

4. validate_markdown

Validate markdown before PDF generation.

await validate_markdown({
  content: "# Document\n\n...",
  check_images: true,
  check_links: true
});

5. create_custom_style

Create a custom PDF style with formatting preferences and writing prompts.

await create_custom_style({
  style_name: "annual_report",
  description: "Professional annual report style",
  prompt: "Format as an annual report with executive summary, metrics, and professional tone",
  theme: "professional",
  custom_css: "/* Additional styling */",
  format: "A4",
  include_toc: true,
  page_numbers: true
});

6. generate_pdf_with_style

Generate a PDF using a saved custom style. PDFs are saved to your Downloads folder by default.

await generate_pdf_with_style({
  style_name: "annual_report",
  content: "# Annual Report 2024\n\n...",
  output_path: "annual_report_2024.pdf"  // Saves to ~/Downloads/annual_report_2024.pdf
});

7. list_custom_styles

List all available custom styles.

const { styles } = await list_custom_styles();
// Returns array of style summaries with names, descriptions, and themes

Themes

Default

Clean and readable typography perfect for general documentation.

Professional

Corporate styling with letterhead design, ideal for business reports.

Minimal

Distraction-free design with generous whitespace for technical docs.

Dark

High-contrast theme optimized for presentations and screen viewing.

Custom Styles

The PDF server now supports saving custom styles that combine formatting preferences, CSS styling, and writing prompts. This allows you to create consistent document types like annual reports, technical documentation, or newsletters.

Pre-built Custom Styles

The server includes several example styles:

  • annual_report: Professional annual report with executive formatting
  • technical_documentation: Clean technical docs with code highlighting
  • presentation_slides: Slide-style formatting for presentations
  • research_paper: Academic paper formatting
  • newsletter: Modern newsletter with columns

Creating Custom Styles

Custom styles can include:

  • Writing prompts: Instructions for how content should be formatted
  • Theme selection: Base theme to build upon
  • Custom CSS: Additional styling rules
  • Page settings: Format, orientation, margins
  • Features: TOC, page numbers, headers/footers

Example:

await create_custom_style({
  style_name: "project_proposal",
  description: "Professional project proposal format",
  prompt: "Format as a project proposal with objectives, timeline, budget sections",
  theme: "professional",
  custom_css: ".budget-table { ... }",
  format: "Letter",
  include_toc: true,
  page_numbers: true,
  header: "<div>Project Proposal</div>"
});

Custom Styling

Use CSS classes in your markdown with markdown-it-attrs:

# Title {.center}

This is an info box {.info-box}

![Image](path.jpg){.img-shadow .img-rounded}

Available CSS classes:

  • .page-break - Force page break
  • .no-break - Prevent page break
  • .center, .right - Text alignment
  • .info-box, .warning-box, .error-box, .success-box - Callout boxes
  • .img-shadow, .img-rounded, .img-border - Image styling

PDF Options

{
  // Page settings
  format: 'A4',              // A4, Letter, Legal, etc.
  orientation: 'portrait',   // portrait or landscape
  margin: {
    top: '1in',
    right: '1in',
    bottom: '1in',
    left: '1in'
  },
  
  // Styling
  theme: 'professional',     // Theme name
  custom_css: '...',        // Additional CSS
  
  // Content
  include_toc: true,        // Table of contents
  toc_depth: 3,            // TOC heading depth
  page_numbers: true,       // Show page numbers
  
  // Images
  image_quality: 85,        // JPEG quality
  max_image_width: 800,     // Max width in pixels
  
  // Advanced
  wait_for_network: true,   // Wait for images
  print_background: true    // Include backgrounds
}

Example Usage

Professional Report

// First, embed images (supports local files, URLs, and base64)
const { processed_markdown } = await embed_images({
  markdown_content: reportContent,
  image_sources: [
    {
      placeholder: '[HERO_IMAGE]',
      source: '/Users/username/Downloads/hero.png',  // Local file
      alignment: 'full-width'
    },
    {
      placeholder: '[LOGO]',
      source: 'https://company.com/logo.png',  // Remote URL
      alignment: 'center'
    },
    {
      placeholder: '[CHART]',
      source: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB...',  // Base64
      caption: 'Sales Data',
      alignment: 'center'
    }
  ],
  options: {
    auto_optimize: true,
    quality: 90
  }
});

// Then generate PDF
await generate_pdf({
  content: processed_markdown,
  output_path: 'report.pdf',  // Saves to Downloads
  options: {
    theme: 'professional',
    include_toc: true,
    page_numbers: true,
    header: '<div style="text-align: right">Q4 2024 Report</div>',
    footer: '<div style="text-align: center">Confidential</div>'
  }
});

Technical Documentation

await generate_pdf({
  content: technicalDocs,
  output_path: 'docs.pdf',  // Saves to Downloads
  options: {
    theme: 'minimal',
    include_toc: true,
    toc_depth: 4,
    enable_javascript: false
  }
});

File Structure

pdf-mcp-server/
├── src/
│   ├── index.js              # MCP server entry point
│   ├── pdf-generator.js      # Core PDF generation
│   ├── markdown-processor.js # Markdown processing
│   ├── image-processor.js    # Image optimization
│   ├── template-manager.js   # Template system
│   └── themes/              # Built-in themes
├── templates/               # User templates
├── temp/                   # Temporary files
└── docs/                   # Documentation

Requirements

  • Node.js 18+
  • Playwright browsers (auto-installed)

License

ISC

Contributing

Pull requests are welcome! Please read the contributing guidelines first.

Support

For issues and feature requests, please use the GitHub issue tracker.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
ChatWiseThe second fastest AI chatbot™
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
DeepChatYour AI Partner on Desktop
Amap Maps高德地图官方 MCP Server
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Playwright McpPlaywright MCP server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
WindsurfThe new purpose-built IDE to harness magic
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
CursorThe AI Code Editor
Serper MCP ServerA Serper MCP Server
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.