mcpField
P
PDF Generator MCP Server

PDF Generator MCP Server

本地服务
github.com/FabianGenell文件与存储373 周前更新

关于 PDF Generator MCP Server

PDF Generator MCP Server 将 Markdown 转为带样式的 PDF,适用于制作报告、文档等格式化内容。它结合可复用主题与样式、图片处理和 Markdown 验证。

主要功能

  1. 01将 Markdown 生成 PDF
  2. 02内置主题和 PDF 选项
  3. 03嵌入并优化图片
  4. 04创建可复用模板和样式
  5. 05验证 Markdown 和链接
  6. 06添加页眉、页脚和页码

适用场景

  1. 01生成带目录的主题报告
  2. 02将技术文档制作成 PDF
  3. 03嵌入文件、URL 或数据 URL 中的图片
  4. 04在多份文档中复用统一样式

MCP 相关

向 MCP 客户端提供 PDF 生成、图片嵌入、模板与样式管理以及 Markdown 验证工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"pdf-mcp-server-fabiangenell": {
"command": "npx",
"args": [
"-y",
"github:FabianGenell/pdf-mcp-server"
]
}
}
}
启动命令npx -y github:FabianGenell/pdf-mcp-server

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmgithub:FabianGenell/pdf-mcp-server

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

PDF 生成器 MCP 服务

一款功能强大的 MCP(模型上下文协议)服务,可将 Markdown 内容生成为专业 PDF,并支持自定义样式、图像和多种格式选项。

功能

  • 🎨 多种内置主题:默认、专业、简约和深色主题
  • 📸 智能图像处理:自动优化、缓存和嵌入
  • 📄 高级 PDF 选项:页眉、页脚、页码、目录生成
  • 🎯 模板系统:创建并复用自定义模板
  • ✅ Markdown 验证:生成前检查内容
  • 🚀 性能优化:复用浏览器实例、缓存图像
  • 💼 自定义样式:保存并复用带有提示词和格式设置的自定义 PDF 样式

安装

使用 GitHub 上的 npx 快速开始(推荐)

无需安装!直接添加到 Claude 桌面配置中:

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

就这样!服务会自动下载并运行。

备选方案:本地开发
# 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"]
    }
  }
}

可用工具

1. generate_pdf

根据 Markdown 内容生成 PDF。PDF 默认保存到“下载”文件夹。

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
  }
});

注意:如果只提供文件名或相对路径,PDF 将保存到“下载”文件夹。若要保存到其他位置,请使用绝对路径。

2. embed_images

处理并优化 Markdown 中的图像并将其嵌入。支持本地路径、URL 和 base64 数据 URL。

图像来源类型

本地文件(来自你的计算机):

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"
  }]
});

远程 URL:

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 数据 URL:

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 指南

对于 AI Agent,可以通过以下三种方式提供图像:

  1. 本地计算机路径:使用绝对路径,例如 /Users/username/Documents/image.png 或 C:\Users\username\Documents\image.png
  2. 在线图像:使用直接 URL,例如 https://example.com/image.png
  3. 生成/上传的图像:使用以 data:image/[type];base64,[data] 开头的 base64 数据 URL

所有图像类型都会自动优化、缓存,并调整为适合 PDF 的尺寸,以提升性能。图像高度会自动限制为页面高度的 70%,以确保布局正确。

3. create_styled_template

创建可复用模板,确保样式一致。

await create_styled_template({
  template_name: "company-report",
  css_content: "/* Custom CSS */",
  html_template: ""
});
4. validate_markdown

在生成 PDF 前验证 Markdown。

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

创建包含格式偏好和写作提示词的自定义 PDF 样式。

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

使用已保存的自定义样式生成 PDF。PDF 默认保存到“下载”文件夹。

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

列出所有可用的自定义样式。

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

主题

默认

整洁易读的字体排版,非常适合一般文档。

专业

采用信头设计的企业风格,适合商业报告。

简约

无干扰设计,为技术文档留出充足留白。

深色

高对比度主题,针对演示和屏幕浏览进行了优化。

自定义样式

PDF 服务现已支持保存自定义样式,这些样式可结合格式偏好、CSS 样式和写作提示词。这样,你就可以创建风格一致的文档类型,例如年度报告、技术文档或新闻简报。

预置自定义样式

服务包含多个示例样式:

  • annual_report:采用高管格式的专业年度报告
  • technical_documentation:带代码高亮的简洁技术文档
  • presentation_slides:适用于演示文稿的幻灯片式格式
  • research_paper:学术论文格式
  • newsletter:采用分栏排版的现代新闻简报
创建自定义样式

自定义样式可以包含:

  • 写作提示词:说明内容应如何格式化
  • 主题选择:作为样式基础的主题
  • 自定义 CSS:附加样式规则
  • 页面设置:格式、方向、页边距
  • 功能:目录、页码、页眉/页脚

示例:

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>"
});

自定义样式

使用 markdown-it-attrs 在 Markdown 中添加 CSS 类:

# Title {.center}

This is an info box {.info-box}

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

可用的 CSS 类:

  • .page-break - 强制分页
  • .no-break - 防止分页
  • .center、.right - 文本对齐
  • .info-box、.warning-box、.error-box、.success-box - 提示框
  • .img-shadow、.img-rounded、.img-border - 图片样式

PDF 选项

{
  // 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
}

使用示例

专业报告
// 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>'
  }
});
技术文档
await generate_pdf({
  content: technicalDocs,
  output_path: 'docs.pdf',  // Saves to Downloads
  options: {
    theme: 'minimal',
    include_toc: true,
    toc_depth: 4,
    enable_javascript: false
  }
});

文件结构

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

要求

  • Node.js 18+
  • Playwright 浏览器(自动安装)

许可证

ISC

参与贡献

欢迎提交拉取请求!请先阅读贡献指南。

支持

如有问题或功能请求,请使用 GitHub 问题跟踪器。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。