PDF 轉 Markdown API

將 PDF 文檔轉換為 Markdown 格式,支持自動圖片提取

概述

PDF 轉 Markdown API 可以將 PDF 文檔轉換為 Markdown 格式,支持自動圖片提取和託管。 它使用統一的 JSON 請求格式,支持 URL 引用或 base64 編碼的文檔數據。

身份驗證

API 支持以下身份驗證方法:

  • API 密鑰: 通過查詢參數傳遞您的 API 密鑰 ?key=YOUR_API_KEY

將 PDF 轉換為 Markdown

將 PDF 文檔轉換為 Markdown 格式,支持自動圖片提取。

請求

POST /api/pdf-to-markdown

參數:

參數類型必需描述
documentobject文檔對象
document.typestring固定值 "document_url"
document.document_urlstringPDF 文檔 URL 或 base64 數據
filenamestring文件名(建議在使用 base64 數據時提供)
keystringAPI 密鑰(查詢參數,已登錄用戶可選)

示例:

使用 PDF URL:

curl -X POST "https://llmocr.com/api/pdf-to-markdown?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "type": "document_url",
      "document_url": "https://llmocr.com/document.pdf"
    }
  }'

使用 Base64 PDF 數據:

curl -X POST "https://llmocr.com/api/pdf-to-markdown?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "type": "document_url",
      "document_url": "data:application/pdf;base64,JVBERi0xLjQK..."
    },
    "filename": "my-document.pdf"
  }'

響應

參數:

參數類型描述
idstring數據庫記錄 ID
filenamestring文件名
contentstring完整的 Markdown 內容(包含嵌入圖片)
formatstring輸出格式,固定為 "markdown"
total_pagesnumberPDF 總頁數
pages_shownnumber響應中包含的頁面數量
is_partialboolean是否因訂閱限制而包含部分內容
remaining_pagesnumber由於限制未顯示的頁面數量(僅在 is_partial 為 true 時出現)
messagestring關於訂閱限制的信息消息(僅在 is_partial 為 true 時出現)
timestampnumber處理完成時間戳
payloadstringAPI 端點 URL

示例:

{
  "id": "67890",
  "filename": "document.pdf",
  "content": "# 文檔標題\n\n包含圖片的文檔內容...\n\n![圖片](https://storage.llmocr.com/image.jpg)",
  "format": "markdown",
  "total_pages": 29,
  "pages_shown": 21,
  "is_partial": true,
  "remaining_pages": 8,
  "message": "根據您的可用訂閱顯示 29 頁中的 21 頁。所有 29 頁都已保存,當您有更多訂閱頁面時,您可以解鎖剩餘的 8 頁。",
  "timestamp": 1758871660489,
  "payload": "https://llmocr.com/api/pdf-to-markdown?key=YOUR_API_KEY"
}
PDF 轉 Markdown API - LLMOCR Developer Guide