跳至主要內容

API 參考

強大、簡潔的 RESTful API,幾行程式碼即可實現專業的 PDF 轉電子書功能

API 請求

基礎 URL:
https://fusion-api.oomol.com/v1
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 的過程。

在 GitHub 上查看

安裝

pip install pdf-craft-sdk

基本用法

from pdf_craft_sdk import PDFCraftClient
# Initialize the client
client = PDFCraftClient(api_key="YOUR_API_KEY")
# Convert a local PDF to Markdown
try:
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, UploadProgress
def 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 tracking
download_url = client.convert_local_pdf(
"large_document.pdf",
progress_callback=on_progress
)

遠端 PDF 轉換

from pdf_craft_sdk import PDFCraftClient, FormatType
client = PDFCraftClient(api_key="YOUR_API_KEY")
# Convert remote PDF to EPUB
download_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, FormatType
client = PDFCraftClient(api_key="YOUR_API_KEY")
# Step 1: Upload file
cache_url = client.upload_file("document.pdf")
# Step 2: Submit conversion task
task_id = client.submit_conversion(
cache_url,
format_type=FormatType.MARKDOWN
)
print(f"Task submitted. ID: {task_id}")
# Step 3: Wait for completion
download_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, PollingStrategy
client = PDFCraftClient(api_key="YOUR_API_KEY")
# Example with custom polling configuration
download_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 minutes
check_interval_ms=2000, # Initial polling interval: 2 seconds
max_check_interval_ms=10000, # Maximum polling interval: 10 seconds
backoff_factor=PollingStrategy.EXPONENTIAL # or 1.5
)

TypeScript SDK

用於與 PDF Craft API 互動的 TypeScript SDK。它透過處理身分驗證、任務提交和結果輪詢,簡化了將 PDF 轉換為 Markdown 或 EPUB 的過程。

在 GitHub 上檢視

安裝

npm install pdf-craft-sdk-ts
# or
yarn 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 file
const 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 conversion
const 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 progress
const 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 task
const taskId = await client.submitConversion(
"cache://file.pdf",
FormatType.Markdown
);
console.log(`Task submitted. ID: ${taskId}`);
// Step 2: Poll for completion
const 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 configuration
const 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 minutes
checkIntervalMs: 2000, // Initial polling interval: 2 seconds
maxCheckIntervalMs: 10000, // Maximum polling interval: 10 seconds
backoffFactor: PollingStrategy.Exponential // or use a number like 1.5
});