pdf4me
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePDF4ME
PDF4ME
Comprehensive PDF processing API with 60+ operations: convert, merge, split, compress, OCR, watermark, form filling, digital signatures, and more.
Official docs: https://dev.pdf4me.com/apiv2/documentation/
这是一款功能全面的PDF处理API,提供60余种操作:格式转换、合并、拆分、压缩、OCR识别、添加水印、表单填充、数字签名等。
When to Use
适用场景
Use this skill when you need to:
- Convert documents to/from PDF (Word, Excel, PowerPoint, HTML, images)
- Merge multiple PDFs into one
- Split PDF into multiple files
- Compress PDF to reduce file size
- Add watermarks, stamps, page numbers
- Extract text, tables, or images from PDF
- Fill PDF forms programmatically
- OCR scanned documents
- Protect/unlock PDF with password
- Create barcodes and QR codes
当你需要完成以下操作时,可以使用该工具:
- 将文档与PDF互转(Word、Excel、PowerPoint、HTML、图片)
- 合并多个PDF为单个文件
- 将PDF拆分为多个文件
- 压缩PDF以减小文件体积
- 添加水印、印章、页码
- 从PDF中提取文本、表格或图片
- 以编程方式填充PDF表单
- 对扫描文档进行OCR识别
- 用密码保护/解锁PDF
- 创建条形码和二维码
Prerequisites
前置条件
- Create an account at https://dev.pdf4me.com/
- Get your API key from https://dev.pdf4me.com/dashboard/#/api-keys/
Set environment variable:
bash
export PDF4ME_API_KEY="your-api-key-here"Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
设置环境变量:
bash
export PDF4ME_API_KEY="your-api-key-here"重要提示: 当在包含管道的命令中使用时,请将包含$VAR的命令用$VAR包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
How to Use
使用方法
1. Convert to PDF
1. 转换为PDF
Convert Word, Excel, PowerPoint, images to PDF:
bash
undefined将Word、Excel、PowerPoint、图片转换为PDF:
bash
undefinedConvert a text file to PDF
将文本文件转换为PDF
echo "Hello, PDF4ME!" > /tmp/test.txt
BASE64_CONTENT=$(base64 < /tmp/test.txt)
Write to `/tmp/pdf4me_request.json`:
```json
{
"docContent": "${BASE64_CONTENT}",
"docName": "test.txt"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > /tmp/output.pdfecho "Hello, PDF4ME!" > /tmp/test.txt
BASE64_CONTENT=$(base64 < /tmp/test.txt)
写入`/tmp/pdf4me_request.json`:
```json
{
"docContent": "${BASE64_CONTENT}",
"docName": "test.txt"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > /tmp/output.pdf2. HTML to PDF
2. HTML转PDF
Convert HTML content to PDF:
bash
HTML_CONTENT=$(echo '<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>' | base64)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${HTML_CONTENT}",
"docName": "test.html",
"layout": "Portrait",
"format": "A4"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertHtmlToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' --output /tmp/from-html.pdf将HTML内容转换为PDF:
bash
HTML_CONTENT=$(echo '<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>' | base64)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${HTML_CONTENT}",
"docName": "test.html",
"layout": "Portrait",
"format": "A4"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertHtmlToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' --output /tmp/from-html.pdf3. URL to PDF
3. URL转PDF
Convert a webpage to PDF:
Write to :
/tmp/pdf4me_request.jsonjson
{
"webUrl": "https://example.com"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertUrlToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' > /tmp/webpage.pdf将网页转换为PDF:
写入:
/tmp/pdf4me_request.jsonjson
{
"webUrl": "https://example.com"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ConvertUrlToPdf" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' > /tmp/webpage.pdf4. Merge PDFs
4. 合并PDF
Combine multiple PDFs into one:
bash
PDF1_BASE64=$(base64 < file1.pdf)
PDF2_BASE64=$(base64 < file2.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": ["${PDF1_BASE64}", "${PDF2_BASE64}"],
"docName": "merged.pdf"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Merge" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > merged.pdf将多个PDF合并为一个:
bash
PDF1_BASE64=$(base64 < file1.pdf)
PDF2_BASE64=$(base64 < file2.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": ["${PDF1_BASE64}", "${PDF2_BASE64}"],
"docName": "merged.pdf"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Merge" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > merged.pdf5. Split PDF
5. 拆分PDF
Split PDF by page ranges:
bash
PDF_BASE64=$(base64 < input.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"splitAction": "splitAfterPage",
"splitAfterPage": 2
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Split" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'按页面范围拆分PDF:
bash
PDF_BASE64=$(base64 < input.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"splitAction": "splitAfterPage",
"splitAfterPage": 2
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Split" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'6. Compress PDF
6. 压缩PDF
Reduce PDF file size:
bash
PDF_BASE64=$(base64 < large.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "large.pdf"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Compress" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > compressed.pdf减小PDF文件体积:
bash
PDF_BASE64=$(base64 < large.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "large.pdf"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/Compress" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > compressed.pdf7. PDF to Word
7. PDF转Word
Convert PDF to editable Word document:
bash
PDF_BASE64=$(base64 < input.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/PdfToWord" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > output.docx将PDF转换为可编辑的Word文档:
bash
PDF_BASE64=$(base64 < input.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/PdfToWord" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > output.docx8. PDF to Images
8. PDF转图片
Create thumbnails/images from PDF pages:
bash
PDF_BASE64=$(base64 < input.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"imageFormat": "png",
"width": 800
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/CreateThumbnail" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'从PDF页面生成缩略图/图片:
bash
PDF_BASE64=$(base64 < input.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"imageFormat": "png",
"width": 800
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/CreateThumbnail" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'9. Add Text Stamp/Watermark
9. 添加文本印章/水印
Add text watermark to PDF:
bash
PDF_BASE64=$(base64 < input.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"stampText": "CONFIDENTIAL",
"pages": "all",
"alignX": "center",
"alignY": "middle",
"alpha": 0.3
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/TextStamp" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > stamped.pdf为PDF添加文本水印:
bash
PDF_BASE64=$(base64 < input.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"stampText": "CONFIDENTIAL",
"pages": "all",
"alignX": "center",
"alignY": "middle",
"alpha": 0.3
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/TextStamp" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > stamped.pdf10. OCR - Extract Text from Scanned PDF
10. OCR识别 - 从扫描PDF提取文本
Make scanned PDFs searchable:
bash
PDF_BASE64=$(base64 < scanned.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "scanned.pdf",
"ocrLanguage": "eng"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/PdfOcr" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > searchable.pdf将扫描PDF转换为可搜索格式:
bash
PDF_BASE64=$(base64 < scanned.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "scanned.pdf",
"ocrLanguage": "eng"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/PdfOcr" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > searchable.pdf11. Protect PDF with Password
11. 用密码保护PDF
bash
PDF_BASE64=$(base64 < input.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"password": "secret123"
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ProtectDocument" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > protected.pdfbash
PDF_BASE64=$(base64 < input.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"password": "secret123"
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ProtectDocument" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > protected.pdf12. Extract Pages
12. 提取页面
Extract specific pages from PDF:
bash
PDF_BASE64=$(base64 < input.pdf)Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"pageNrs": [1, 3, 5]
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ExtractPages" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > extracted.pdf从PDF中提取指定页面:
bash
PDF_BASE64=$(base64 < input.pdf)写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "${PDF_BASE64}",
"docName": "input.pdf",
"pageNrs": [1, 3, 5]
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/ExtractPages" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json' | jq -r '.docContent' | base64 -d > extracted.pdfAPI Endpoints
API接口
| Category | Endpoint | Description |
|---|---|---|
| Convert | | Word/Excel/PPT/Image → PDF |
| HTML → PDF | |
| URL → PDF | |
| Markdown → PDF | |
| PDF → Word | |
| PDF → Excel | |
| PDF → PowerPoint | |
| Merge/Split | | Merge multiple PDFs |
| Split PDF | |
| Extract specific pages | |
| Optimize | | Compress PDF |
| Optimize for web | |
| Edit | | Add text watermark |
| Add image watermark | |
| Add page numbers | |
| Rotate pages | |
| Extract | | PDF → Images |
| Extract images/fonts | |
| Extract tables | |
| OCR | | OCR scanned PDFs |
| Security | | Password protect |
| Remove password | |
| Forms | | Fill form fields |
| Extract form data | |
| Barcode | | Generate barcode |
| Add barcode to PDF | |
| Read barcode from PDF |
| 分类 | 接口地址 | 描述 |
|---|---|---|
| 格式转换 | | Word/Excel/PPT/图片 → PDF |
| HTML → PDF | |
| URL → PDF | |
| Markdown → PDF | |
| PDF → Word | |
| PDF → Excel | |
| PDF → PowerPoint | |
| 合并/拆分 | | 合并多个PDF |
| 拆分PDF | |
| 提取指定页面 | |
| 优化 | | 压缩PDF |
| 优化以适配网页 | |
| 编辑 | | 添加文本水印 |
| 添加图片水印 | |
| 添加页码 | |
| 旋转页面 | |
| 提取 | | PDF → 图片 |
| 提取图片/字体 | |
| 提取表格 | |
| OCR识别 | | 对扫描PDF进行OCR识别 |
| 安全 | | 密码保护 |
| 移除密码 | |
| 表单 | | 填充表单字段 |
| 提取表单数据 | |
| 条形码 | | 生成条形码 |
| 为PDF添加条形码 | |
| 从PDF读取条形码 |
Request Format
请求格式
All endpoints use POST with JSON body:
Write to :
/tmp/pdf4me_request.jsonjson
{
"docContent": "base64-encoded-file",
"docName": "filename.ext",
"...other parameters": "..."
}Then run:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/{endpoint}" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'所有接口均使用POST请求,请求体为JSON格式:
写入:
/tmp/pdf4me_request.jsonjson
{
"docContent": "base64-encoded-file",
"docName": "filename.ext",
"...other parameters": "..."
}然后运行:
bash
bash -c 'curl -s -X POST "https://api.pdf4me.com/api/v2/{endpoint}" --header "Authorization: ${PDF4ME_API_KEY}" --header "Content-Type: application/json" -d @/tmp/pdf4me_request.json'Response Format
响应格式
json
{
"docContent": "base64-encoded-result",
"docName": "output.pdf",
"pageCount": 5
}json
{
"docContent": "base64-encoded-result",
"docName": "output.pdf",
"pageCount": 5
}Guidelines
使用准则
- File Size: Max 20MB per file (varies by plan)
- Base64: All file content must be base64 encoded
- Formats: Supports PDF, Word, Excel, PowerPoint, HTML, images
- OCR Languages: eng, deu, fra, spa, ita, por, etc.
- Rate Limits: Check your plan at https://dev.pdf4me.com/pricing/
- Free Tier: 50 API calls/month
- Postman: Import from https://dev.pdf4me.com/apiv2/documentation/postman/
- 文件大小:单文件最大20MB(根据套餐不同有所差异)
- Base64编码:所有文件内容必须进行Base64编码
- 支持格式:支持PDF、Word、Excel、PowerPoint、HTML、图片
- OCR语言:支持英语、德语、法语、西班牙语、意大利语、葡萄牙语等
- 调用限制:请查看你的套餐详情:https://dev.pdf4me.com/pricing/
- 免费套餐:每月50次API调用
- Postman:从https://dev.pdf4me.com/apiv2/documentation/postman/导入集合
Resources
相关资源
- API Docs: https://dev.pdf4me.com/apiv2/documentation/
- Code Samples: https://github.com/pdf4me/pdf4me-api-samples
- Postman Collection: https://dev.pdf4me.com/apiv2/documentation/postman/
- Dashboard: https://dev.pdf4me.com/dashboard/