README
🚀 @mcp-z/mcp-pdf
@mcp-z/mcp-pdf 是一个用于生成 PDF 的 MCP 服务器,支持文档、布局和图像导出。它提供了多种工具,可满足不同的 PDF 生成需求。
文档链接:https://mcp-z.github.io/mcp-pdf
🚀 快速开始
安装
MCP 支持标准输入输出(stdio)和 HTTP 两种传输方式,以下是对应的配置示例:
Stdio
{
"mcpServers": {
"pdf": {
"command": "npx",
"args": ["-y", "@mcp-z/mcp-pdf"]
}
}
}
HTTP
{
"mcpServers": {
"pdf": {
"type": "http",
"url": "http://localhost:9010/mcp",
"start": {
"command": "npx",
"args": ["-y", "@mcp-z/mcp-pdf", "--port=9010"]
}
}
}
}
start 是 npx @mcp-z/cli up 用于启动 HTTP 服务器的扩展。
使用示例
# 列出可用工具
mcp-z inspect --servers pdf --tools
# 创建一个简单的 PDF
mcp-z call pdf pdf-document '{"content":["Hello from MCP"]}'
✨ 主要特性
- PDF 生成:可从文本或布局生成 PDF。
- 图像渲染:将 PDF 页面渲染为图像。
- 文本测量:在布局前测量文本的宽度和高度。
💻 使用示例
pdf-resume
该工具可从 JSON Resume 格式生成专业简历。
// 示例:自定义简历部分顺序
await client.callTool('pdf-resume', {
resume: { /* JSON Resume 数据 */ },
sections: {
sections: [
{ source: 'basics', render: 'header' },
{ source: 'basics.summary', title: 'Summary' },
{ source: 'work', title: 'Experience' },
{ source: 'skills', title: 'Skills' },
{ source: 'education', title: 'Education' }
]
}
});
pdf-layout
该工具可创建具有精确定位和 Yoga 弹性布局的 PDF。
// 示例:创建一个两列布局的 PDF
await client.callTool('pdf-layout', {
pageSetup: { backgroundColor: '#fffef5' },
content: [
{ type: 'heading', text: 'SUMMER FESTIVAL 2024', align: 'center', fontSize: 28, y: 50 },
{ type: 'text', text: 'July 15-17 | Central Park', align: 'center', y: 90 },
{
type: 'group',
direction: 'row',
gap: 20,
x: 54,
y: 130,
children: [
{
type: 'group',
flex: 1,
border: { color: '#2196f3', width: 2 },
padding: 15,
children: [
{ type: 'heading', text: 'MUSIC', align: 'center', fontSize: 18 },
{ type: 'text', text: 'Live bands all weekend' },
{ type: 'text', text: '- Main Stage' },
{ type: 'text', text: '- Acoustic Tent' }
]
},
{
type: 'group',
flex: 1,
border: { color: '#4caf50', width: 2 },
padding: 15,
children: [
{ type: 'heading', text: 'FOOD', align: 'center', fontSize: 18 },
{ type: 'text', text: '50+ local vendors' },
{ type: 'text', text: '- Food Court' },
{ type: 'text', text: '- Craft Beers' }
]
}
]
},
{
type: 'group',
width: 300,
align: 'center',
y: 400,
border: { color: '#ff9800', width: 2 },
padding: 15,
background: '#fff8e1',
children: [
{ type: 'heading', text: 'TICKETS', align: 'center', fontSize: 16 },
{ type: 'text', text: 'Early Bird: $25', align: 'center' },
{ type: 'text', text: 'At Door: $35', align: 'center' }
]
}
]
});
📚 详细文档
可用工具
pdf-resume
从 JSON Resume 格式生成专业简历。
参数说明:
| 参数 | 类型 | 是否必需 | 详情 |
|------|------|------|------|
| filename | string | 可选 | PDF 文件名(默认为 "resume.pdf") |
| resume | object | 必需 | JSON Resume 模式数据 |
| sections | object | 可选 | 部分排序和字段模板 |
| layout | object | 可选 | 空间布局(单列或双列) |
| styling | object | 可选 | 排版和间距选项 |
| font | string | 可选 | 自定义字体 |
| pageSize | string | 可选 | 页面大小(默认:"LETTER") |
| backgroundColor | string | 可选 | 页面背景颜色 |
简历模式部分:
basics- 姓名、联系方式、摘要、所在地work- 工作经历及亮点education- 学位和院校projects- 个人/专业项目skills- 按类别分组的技能awards,certificates,languages,volunteer,publications,interests,references
pdf-layout
创建具有精确定位和 Yoga 弹性布局的 PDF。
参数说明:
| 参数 | 类型 | 是否必需 | 详情 |
|------|------|------|------|
| filename | string | 可选 | PDF 文件名(默认为 "document.pdf") |
| title | string | 可选 | 文档元数据 |
| author | string | 可选 | 文档元数据 |
| pageSetup | object | 可选 | 页面配置 |
| content | array | 必需 | 内容项 |
| layout | object | 可选 | 布局选项 |
pdf-document
创建具有自动分页功能的流式 PDF 文档。
pdf-image
将 PDF 页面渲染为 PNG 图像,用于预览或导出。
text-measure
在布局前测量文本的宽度和高度。
外部资源
提示
- resource-fetching:资源获取相关提示。
🔧 技术细节
传输方式
MCP 支持标准输入输出(stdio)和 HTTP 两种传输方式,可根据实际需求选择合适的方式进行配置。
工具实现
各个工具(如 pdf-resume、pdf-layout 等)都有其特定的参数和使用方式,通过传入不同的参数可以实现不同的功能。例如,pdf-resume 工具通过传入 resume 参数来指定简历数据,通过 sections 参数来控制简历部分的显示顺序和格式。
布局引擎
pdf-layout 工具使用 Yoga 弹性布局引擎,通过 type: 'group' 创建弹性容器,支持多种布局模式,如两列布局、三列布局等。同时,该工具还支持精确的定位和混合定位,可满足不同的布局需求。
文本处理
支持 Emoji 和 Unicode 文本,Emoji 以嵌入式图像的形式渲染,Unicode 文本在主要脚本中都能正常显示。同时,提供了 text-measure 工具,可在布局前测量文本的宽度和高度,方便进行布局调整。
微信扫一扫