Loading...
  • 建構
  • 管理
  • 模型與定價
  • 客戶端 SDK
  • API 參考
Search...
⌘K
Log in
PDF 支援
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
建構/處理檔案

PDF 支援

使用 Claude 處理 PDF。從您的文件中提取文字、分析圖表並理解視覺內容。

This feature is eligible for Zero Data Retention (ZDR). When your organization has a ZDR arrangement, data sent through this feature is not stored after the API response is returned.

您可以詢問 Claude 關於您提供的 PDF 中的任何文字、圖片、圖表和表格。一些範例使用案例:

  • 分析財務報告並理解圖表/表格
  • 從法律文件中提取關鍵資訊
  • 文件翻譯協助
  • 將文件資訊轉換為結構化格式

開始之前

檢查 PDF 要求

Claude 適用於任何標準 PDF。確保您的請求大小符合這些要求:

要求限制
最大請求大小32 MB (因平台而異)
每個請求的最大頁數600(對於具有 200k 代幣上下文視窗的模型為 100)
格式標準 PDF(無密碼/加密)

兩個限制都適用於整個請求負載,包括與 PDF 一起發送的任何其他內容。對於大型 PDF,請考慮使用 Files API 上傳並按 file_id 引用以保持請求負載較小。

密集 PDF(許多小字體頁面、複雜表格或繁重圖形)可能會在達到頁面限制之前填滿上下文視窗。包含大型 PDF 的請求也可能在達到頁面限制之前失敗,即使使用 Files API 也是如此。嘗試將文件分割成多個部分;對於大型檔案,由於每個頁面都作為影像處理,縮減嵌入影像也可以幫助。

由於 PDF 支援依賴於 Claude 的視覺功能,它受到與其他視覺任務相同的 限制和注意事項。

支援的平台和模型

PDF 支援目前通過直接 API 存取和 Google Vertex AI 支援。所有 活躍模型 都支援 PDF 處理。

PDF 支援現已在 Amazon Bedrock 上提供,具有以下注意事項:

Amazon Bedrock PDF 支援

通過 Amazon Bedrock 的 Converse API 使用 PDF 支援時,有兩種不同的文件處理模式:

重要: 要在 Converse API 中存取 Claude 的完整視覺 PDF 理解功能,您必須啟用引用。如果未啟用引用,API 將回退到僅基本文字提取。深入瞭解 使用引用。

文件處理模式

  1. Converse Document Chat(原始模式 - 僅文字提取)

    • 提供來自 PDF 的基本文字提取
    • 無法分析 PDF 中的影像、圖表或視覺佈局
    • 3 頁 PDF 大約使用 1,000 個代幣
    • 未啟用引用時自動使用
  2. Claude PDF Chat(新模式 - 完整視覺理解)

    • 提供 PDF 的完整視覺分析
    • 可以理解和分析圖表、圖形、影像和視覺佈局
    • 將每個頁面作為文字和影像處理以進行全面理解
    • 3 頁 PDF 大約使用 7,000 個代幣
    • 需要在 Converse API 中啟用引用

關鍵限制

  • Converse API:視覺 PDF 分析需要啟用引用。目前沒有選項可以在不使用引用的情況下使用視覺分析(與 InvokeModel API 不同)。
  • InvokeModel API:提供對 PDF 處理的完全控制,無需強制引用。

常見問題

如果客戶報告在使用 Converse API 時 Claude 無法看到其 PDF 中的影像或圖表,他們可能需要啟用引用標誌。沒有它,Converse 將回退到僅基本文字提取。

這是 Converse API 的已知限制。對於需要無引用視覺 PDF 分析的應用程式,請考慮改用 InvokeModel API。

對於非 PDF 檔案(如 .csv、.xlsx、.docx、.md 或 .txt 檔案),請參閱 使用其他檔案格式。


使用 Claude 處理 PDF

發送您的第一個 PDF 請求

讓我們從使用 Messages API 的簡單範例開始。您可以通過三種方式向 Claude 提供 PDF:

  1. 作為對線上託管 PDF 的 URL 引用
  2. 作為 document 內容區塊中的 base64 編碼 PDF
  3. 通過來自 Files API 的 file_id

選項 1:基於 URL 的 PDF 文件

最簡單的方法是直接從 URL 引用 PDF:

client = anthropic.Anthropic()
message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "document",
                    "source": {
                        "type": "url",
                        "url": "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf",
                    },
                },
                {"type": "text", "text": "What are the key findings in this document?"},
            ],
        }
    ],
)

print(message.content)

選項 2:Base64 編碼的 PDF 文件

如果您需要從本地系統發送 PDF 或 URL 不可用時:

import base64
import httpx

# First, load and encode the PDF
pdf_url = "https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"
pdf_data = base64.standard_b64encode(httpx.get(pdf_url).content).decode("utf-8")

# Alternative: Load from a local file
# with open("document.pdf", "rb") as f:
#     pdf_data = base64.standard_b64encode(f.read()).decode("utf-8")

# Send to Claude using base64 encoding
client = anthropic.Anthropic()
message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "document",
                    "source": {
                        "type": "base64",
                        "media_type": "application/pdf",
                        "data": pdf_data,
                    },
                },
                {"type": "text", "text": "What are the key findings in this document?"},
            ],
        }
    ],
)

print(message.content)

選項 3:Files API

對於您將重複使用的 PDF,或當您想避免編碼開銷時,請使用 Files API:

client = anthropic.Anthropic()

# Upload the PDF file
with open("document.pdf", "rb") as f:
    file_upload = client.beta.files.upload(file=("document.pdf", f, "application/pdf"))

# Use the uploaded file in a message
message = client.beta.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    betas=["files-api-2025-04-14"],
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "document",
                    "source": {"type": "file", "file_id": file_upload.id},
                },
                {"type": "text", "text": "What are the key findings in this document?"},
            ],
        }
    ],
)

print(message.content)

PDF 支援的運作方式

當您向 Claude 發送 PDF 時,會發生以下步驟:

  1. 1

    系統提取文件的內容。

    • 系統將文件的每一頁轉換為影像。
    • 從每一頁提取文字並與每一頁的影像一起提供。
  2. 2

    Claude 分析文字和影像以更好地理解文件。

    • 文件作為文字和影像的組合提供以供分析。
    • 這允許使用者詢問 PDF 的視覺元素的見解,例如圖表、圖表和其他非文字內容。
  3. 3

    Claude 回應,如果相關則引用 PDF 的內容。

    Claude 可以在回應時引用文字和視覺內容。您可以通過整合 PDF 支援與以下內容來進一步改進效能:

    • 提示快取:改進重複分析的效能。
    • 批次處理:用於大量文件處理。
    • 工具使用:從文件中提取特定資訊以用作工具輸入。

估計您的成本

PDF 檔案的代幣計數取決於從文件中提取的總文字以及頁數:

  • 文字代幣成本:每頁通常使用 1,500-3,000 個代幣,具體取決於內容密度。標準 API 定價適用,無額外 PDF 費用。
  • 影像代幣成本:由於每一頁都轉換為影像,應用相同的 基於影像的成本計算。

您可以使用 代幣計數 來估計您特定 PDF 的成本。


最佳化 PDF 處理

改進效能

遵循這些最佳實踐以獲得最佳結果:

  • 在請求中將 PDF 放在文字之前
  • 使用標準字體
  • 確保文字清晰易讀
  • 將頁面旋轉到正確的直立方向
  • 在提示中使用邏輯頁碼(來自 PDF 檢視器)
  • 在需要時將大型 PDF 分割成多個部分
  • 為重複分析啟用提示快取

擴展您的實現

對於大量處理,請考慮以下方法:

使用提示快取

快取 PDF 以改善重複查詢的效能:

client = anthropic.Anthropic()
# ...
message = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "document",
                    "source": {
                        "type": "base64",
                        "media_type": "application/pdf",
                        "data": pdf_data,
                    },
                    "cache_control": {"type": "ephemeral"},
                },
                {"type": "text", "text": "Analyze this document."},
            ],
        }
    ],
)

處理文件批次

使用訊息批次 API 進行大量工作流程:

client = anthropic.Anthropic()
# ...
message_batch = client.messages.batches.create(
    requests=[
        {
            "custom_id": "doc1",
            "params": {
                "model": "claude-opus-4-7",
                "max_tokens": 1024,
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {
                                "type": "document",
                                "source": {
                                    "type": "base64",
                                    "media_type": "application/pdf",
                                    "data": pdf_data,
                                },
                            },
                            {"type": "text", "text": "Summarize this document."},
                        ],
                    }
                ],
            },
        }
    ]
)

後續步驟

試試 PDF 範例

在食譜中探索 PDF 處理的實際範例。

檢視 API 參考

查看 PDF 支援的完整 API 文件。

Was this page helpful?

  • 檢查 PDF 要求
  • Amazon Bedrock PDF 支援
  • 使用 Claude 處理 PDF
  • 發送您的第一個 PDF 請求
  • PDF 支援的運作方式
  • 最佳化 PDF 處理