API 文档
通过编程方式将 Markdown 转换为 PDF。我们的 REST API 让您可以通过单个 HTTP 请求从 Markdown 内容生成专业、有样式的 PDF。
快速开始
使用简单的 curl 命令在 30 秒内生成 PDF。
获取您的 API 密钥
在您的控制面板中的 API Keys 下生成一个密钥。
编写 Markdown
支持任何有效的 Markdown — 标题、列表、代码块、表格、图片。
发送请求
使用您的密钥和 Markdown 发送 POST 请求。将返回一个 PDF。
curl -X POST https://markdowntopdfconverter.com/api/v1/convert \
-H "Authorization: Bearer mp_live_your_api_key_here" \
-H "Content-Type: application/json" \
-d '{"markdown": "# Hello World\n\nThis is a **test**.", "templateId": "clean"}' \
-o output.pdf身份验证
apiDocs.authentication.description
请求头
| 头 | 值 | 说明 |
|---|---|---|
| Authorization | Bearer mp_live_... | 您的 API 密钥,前缀为 Bearer |
| Content-Type | application/json | 所有请求均需要 |
apiDocs.authentication.keyFormat
POST /api/v1/convert
将 Markdown 转换为带样式的 PDF 文档。
请求体
markdownstring必须要转换的 Markdown 内容。最多 200,000 个字符。
templateIdstring可选要使用的模板。其中之一:clean, executive, resume, academic, legal, creative。默认:clean。
filenamestring可选下载的 PDF 文件名称。默认:document.pdf。
localestring可选渲染的区域设置。其中之一:en, es, fr, de, ja, zh-CN, ko, pt-BR, ar, ru, hi, it。默认:en。
customTemplateIdUUID可选保存的自定义模板的 UUID。该模板必须属于 API 密钥的用户。
optionsobject可选转换选项:pageNumbers (boolean), bodyTextColor (hex), headingTextColor (hex), creativeAccent (slate|purple|blue|emerald|rose|amber)。
示例请求
import requests
api_key = "mp_live_your_api_key_here"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
payload = {
"markdown": "# Quarterly Report\n\n## Revenue\n\nRevenue grew **15%** this quarter.",
"templateId": "executive",
"options": {"pageNumbers": True}
}
response = requests.post(
"https://markdowntopdfconverter.com/api/v1/convert",
json=payload,
headers=headers
)
with open("report.pdf", "wb") as f:
f.write(response.content)const response = await fetch(
"https://markdowntopdfconverter.com/api/v1/convert",
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
markdown: "# Invoice\n\n**Amount:** $1,200\n\n| Item | Qty | Price |\n| --- | --- | --- |\n| Widget | 5 | $240 |",
templateId: "clean",
filename: "invoice",
}),
}
);
const blob = await response.blob();
const url = URL.createObjectURL(blob);
// Trigger download
const a = document.createElement("a");
a.href = url;
a.download = "invoice.pdf";
a.click();模板
从六种专业设计的模板中进行选择。每种模板都有独特的排版、间距和颜色方案。
Clean
最简洁、现代的无转角线体设计,整洁的间距。
Executive
带有转角线的标题,专业的海军蓝强调和页码。
Resume
为简历优化的紧凑单列布局。
Academic
带编号的标题、宽敞的间距和 EB Garamond 正文。
Legal
双倍行距的有转角线正文,带正式引用格式。
Creative
粗体 DM Sans 标题,配有可配置的强调颜色。
错误码
每个响应都使用标准 HTTP 状态码。使用它来决定如何处理结果。
| 状态 | 含义 | 操作 |
|---|---|---|
| 200 | 成功 — 返回 PDF | 从响应体中下载 PDF。 |
| 400 | 请求体无效 | 检查您的 JSON 加载是否符合上方的模式。 |
| 401 | API 密钥无效或缺失 | 确认您的 API 密钥已激活并且格式正确。 |
| 402 | API 积分已耗尽 | 从您的控制面板购买更多积分。 |
| 404 | 未找到自定义模板 | 确认 customTemplateId 正确并且属于您。 |
| 415 | Content-Type 错误 | 将 Content-Type 头设为 application/json。 |
| 422 | 无效的转换选项 | 检查您的 options 对象是否符合规范。 |
| 429 | 请求量限制 | 等待并重试。检查 Retry-After 头。 |
| 500 | 服务器错误 | 使用指数退避重试。如果持续发生,请联系支持。 |
API 定价
API 调用按月追踪。每次成功的转换都计入您套餐的月度限额。
$0
25 / month
用于测试和评估。
$9
500 / month
适合个人和小型项目。
$29
1,000 / month
优先生成,通过 API 支持自定义模板。
需要更多?联系我们了解定制企业定价。