API 参考
强大、简洁的 RESTful API,几行代码即可实现专业的 PDF 转电子书功能
API 请求
基础 URL:
https://fusion-api.oomol.com/v1认证
所有请求需要在 Authorization 请求头中携带 API 密钥(格式:Bearer YOUR_API_KEY)
Authorization: Bearer YOUR_API_KEY
POST
/pdf-transform-markdown/submit提交 PDF 转 Markdown 任务
上传 PDF 文件 URL 并提交转换为 Markdown 格式的任务
请求参数
pdfURL- PDF 文件的云端 URL(string,必需,从文件上传接口获取)model- 转换模型(string,必需,固定值为 "gundam")filename- 文件名(不含扩展名,可选),用于用户下载后识别文件ignore_pdf_errors- 是否忽略 PDF 解析错误(可选,默认为 true)ignore_ocr_errors- 是否忽略 OCR 错误(可选,默认为 true)
请求示例
{
"pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf",
"model": "gundam",
"filename": "my-document",
"ignore_pdf_errors": true,
"ignore_ocr_errors": true
}响应示例
{
"success": true,
"sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"
}GET
/pdf-transform-markdown/result/:taskId查询 PDF 转 Markdown 结果
根据任务 ID 查询转换任务的状态和结果
URL 参数
taskId- 任务 ID(从提交接口返回的 sessionID)
响应示例(处理中)
{
"success": true,
"state": "processing",
"progress": 66
}响应示例(已完成)
{
"success": true,
"state": "completed",
"progress": 100,
"data": {
"downloadURL": "https://cdn.oomol.com/result.md"
}
}响应示例(失败)
{
"success": false,
"state": "failed",
"progress": 0,
"error": "转换失败原因"
}POST
/pdf-transform-epub/submit提交 PDF 转 EPUB 任务
上传 PDF 文件 URL 并提交转换为 EPUB 格式的任务
请求参数
pdfURL- PDF 文件的云端 URL(string,必需,从文件上传接口获取)model- 转换模型(string,必需,固定值为 "gundam")filename- 文件名(不含扩展名,可选),用于用户下载后识别文件ignore_pdf_errors- 是否忽略 PDF 解析错误(可选,默认为 true)ignore_ocr_errors- 是否忽略 OCR 错误(可选,默认为 true)
请求示例
{
"pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf",
"model": "gundam",
"filename": "my-document",
"ignore_pdf_errors": true,
"ignore_ocr_errors": true
}响应示例
{
"success": true,
"sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"
}GET
/pdf-transform-epub/result/:taskId查询 PDF 转 EPUB 结果
根据任务 ID 查询转换任务的状态和结果
URL 参数
taskId- 任务 ID(从提交接口返回的 sessionID)
响应示例(处理中)
{
"success": true,
"state": "processing",
"progress": 66
}响应示例(已完成)
{
"success": true,
"state": "completed",
"progress": 100,
"data": {
"downloadURL": "https://cdn.oomol.com/result.epub"
}
}响应示例(失败)
{
"success": false,
"state": "failed",
"progress": 0,
"error": "转换失败原因"
}cURL
# 1. 提交 PDF 转 Markdown 任务curl -X POST https://fusion-api.oomol.com/v1/pdf-transform-markdown/submit \-H "Content-Type: application/json" \-H "Authorization: Bearer YOUR_API_KEY" \-d '{"pdfURL": "https://pdfcraft.ai/examples/api-quickstart.pdf","model": "gundam","filename": "my-document"}'# 响应: {"success": true, "sessionID": "019aa097-f28d-7000-8d56-6a2987a7b144"}# 2. 查询转换结果curl -X GET https://fusion-api.oomol.com/v1/pdf-transform-markdown/result/019aa097-f28d-7000-8d56-6a2987a7b144 \-H "Authorization: Bearer YOUR_API_KEY"# 响应: {"success": true, "state": "completed", "data": {"downloadURL": "https://cdn.oomol.com/result.md"}}
Python SDK
用于与 PDF Craft API 交互的 Python SDK。它通过处理身份验证、任务提交和结果轮询,简化了将 PDF 转换为 Markdown 或 EPUB 的过程。
安装
pip install pdf-craft-sdk
基本用法
from pdf_craft_sdk import PDFCraftClient# Initialize the clientclient = PDFCraftClient(api_key="YOUR_API_KEY")# Convert a local PDF to Markdowntry:download_url = client.convert_local_pdf("document.pdf")print(f"Conversion successful! Download URL: {download_url}")except Exception as e:print(f"An error occurred: {e}")
本地文件上传与进度跟踪
from pdf_craft_sdk import PDFCraftClient, UploadProgressdef on_progress(progress: UploadProgress):print(f"Upload: {progress.percentage:.2f}% - Part {progress.current_part}/{progress.total_parts}")client = PDFCraftClient(api_key="YOUR_API_KEY")# Upload local file with progress trackingdownload_url = client.convert_local_pdf("large_document.pdf",progress_callback=on_progress)
远程 PDF 转换
from pdf_craft_sdk import PDFCraftClient, FormatTypeclient = PDFCraftClient(api_key="YOUR_API_KEY")# Convert remote PDF to EPUBdownload_url = client.convert(pdf_url="https://example.com/file.pdf",format_type=FormatType.EPUB,includes_footnotes=True)print(f"Download URL: {download_url}")
高级用法(分步执行)
from pdf_craft_sdk import PDFCraftClient, FormatTypeclient = PDFCraftClient(api_key="YOUR_API_KEY")# Step 1: Upload filecache_url = client.upload_file("document.pdf")# Step 2: Submit conversion tasktask_id = client.submit_conversion(cache_url,format_type=FormatType.MARKDOWN)print(f"Task submitted. ID: {task_id}")# Step 3: Wait for completiondownload_url = client.wait_for_completion(task_id)print(f"Download URL: {download_url}")
配置选项
- max_wait_ms: 最大等待时间(毫秒),默认 7200000(2小时)
- check_interval_ms: 初始轮询间隔(毫秒),默认 1000
- max_check_interval_ms: 最大轮询间隔(毫秒),默认 5000
- backoff_factor: 轮询间隔递增倍数,或使用 PollingStrategy 枚举(默认 PollingStrategy.EXPONENTIAL / 1.5)
- model: 用于转换的模型,默认 'gundam'
from pdf_craft_sdk import PDFCraftClient, FormatType, PollingStrategyclient = PDFCraftClient(api_key="YOUR_API_KEY")# Example with custom polling configurationdownload_url = client.convert(pdf_url="https://example.com/file.pdf",format_type=FormatType.MARKDOWN,model="gundam",includes_footnotes=True,ignore_pdf_errors=True,ignore_ocr_errors=True,max_wait_ms=600000, # Maximum wait time: 10 minutescheck_interval_ms=2000, # Initial polling interval: 2 secondsmax_check_interval_ms=10000, # Maximum polling interval: 10 secondsbackoff_factor=PollingStrategy.EXPONENTIAL # or 1.5)
TypeScript SDK
用于与 PDF Craft API 交互的 TypeScript SDK。它通过处理身份验证、任务提交和结果轮询,简化了将 PDF 转换为 Markdown 或 EPUB 的过程。
安装
npm install pdf-craft-sdk-ts# oryarn add pdf-craft-sdk-ts
基本用法
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");async function main() {try {const downloadUrl = await client.convert("cache://your-pdf-file.pdf", {formatType: FormatType.Markdown});console.log(`Success! Download: ${downloadUrl}`);} catch (error) {console.error("Error:", error);}}main();
本地文件上传与进度跟踪
import { PDFCraftClient, FormatType, UploadProgress } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");const onProgress = (progress: UploadProgress) => {console.log(`Progress: ${progress.percentage.toFixed(2)}%`);console.log(`Part ${progress.currentPart}/${progress.totalParts}`);};// Upload and convert local fileconst downloadUrl = await client.convertLocalPdf("document.pdf", {formatType: FormatType.Markdown,progressCallback: onProgress,includesFootnotes: true,uploadMaxRetries: 5});
批量处理
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");// Create batch conversionconst files = [{ url: "cache://file1.pdf", fileName: "document1.pdf" },{ url: "cache://file2.pdf", fileName: "document2.pdf" }];const batch = await client.createBatch(files, FormatType.Markdown, false);const result = await client.startBatch(batch.batchId);// Monitor progressconst status = await client.getBatchStatus(batch.batchId);console.log(`Completed: ${status.completedCount}/${status.totalCount}`);
高级用法(分步执行)
import { PDFCraftClient, FormatType } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");// Step 1: Submit taskconst taskId = await client.submitConversion("cache://file.pdf",FormatType.Markdown);console.log(`Task submitted. ID: ${taskId}`);// Step 2: Poll for completionconst downloadUrl = await client.waitForCompletion(taskId,FormatType.Markdown);console.log(`Download URL: ${downloadUrl}`);
配置选项
- formatType: FormatType.Markdown | FormatType.EPUB(默认: FormatType.Markdown)
- model: 使用的模型(默认: 'gundam')
- wait: 是否等待完成(默认: true)
- maxWaitMs: 最大等待时间(毫秒),默认 7200000(2小时)
- checkIntervalMs: 初始轮询间隔(毫秒),默认 1000
- maxCheckIntervalMs: 最大轮询间隔(毫秒),默认 5000
- backoffFactor: 轮询间隔递增倍数,或使用 PollingStrategy 枚举(默认 PollingStrategy.Exponential / 1.5)
import { PDFCraftClient, FormatType, PollingStrategy } from 'pdf-craft-sdk-ts';const client = new PDFCraftClient("YOUR_API_KEY");// Example with custom polling configurationconst downloadUrl = await client.convert("cache://file.pdf", {formatType: FormatType.Markdown,model: "gundam",wait: true,includesFootnotes: true,ignorePdfErrors: true,ignoreOcrErrors: true,maxWaitMs: 600000, // Maximum wait time: 10 minutescheckIntervalMs: 2000, // Initial polling interval: 2 secondsmaxCheckIntervalMs: 10000, // Maximum polling interval: 10 secondsbackoffFactor: PollingStrategy.Exponential // or use a number like 1.5});