PDF support
A user hands you a 40-page PDF contract and asks for the termination clause. A policy analyst uploads a 200-page regulatory filing and wants a summary. A researcher drops a scanned scientific paper with embedded tables and wants the numbers. Traditionally, step one is "find a PDF parsing library, deal with layout issues, extract text, handle tables separately, worry about embedded images." With Claude, step one is "send the PDF."
PDFs, the same way you send images
The PDF upload path is identical to image support — same message structure, same base64 encoding, slightly different field values. If you wrote the image lesson's code, you already know almost everything you need to know about PDFs.
import base64
with open("earth.pdf", "rb") as f:
file_bytes = base64.standard_b64encode(f.read()).decode("utf-8")
messages = []
add_user_message(messages, [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": file_bytes,
},
},
{"type": "text", "text": "Summarise the document in one sentence."},
])
chat(messages)
Four small differences from the image example:
type: "document"instead of"image".media_type: "application/pdf"instead of"image/png".- Variable name
file_bytesinstead ofimage_bytes— cosmetic but clearer when you're juggling multiple file types. - Load the PDF file with the correct
.pdfextension.
Everything else — the user message structure, the text block for your instruction, the chat() call — is the same.
What Claude actually does with a PDF
Claude treats a PDF as a first-class document, not just a bag of text. It extracts and reasons about:
- Text content throughout the document, including headers, footnotes, and body paragraphs.
- Embedded images and charts — it reads figures the same way it reads any other image.
- Tables and their data relationships — column headers, row labels, numeric cells, and the semantic meaning of the layout.
- Document structure — sections, headings, page boundaries, and the hierarchy of the content.
This is genuinely different from pre-Claude PDF extraction, where you'd parse text with pypdf, extract tables with a second library, OCR scanned images with a third, and glue the pieces together with a fragile mess of code. Claude is a one-call replacement for a multi-library document processing stack — for most use cases, you don't need to touch any of those libraries at all.
What you can ask it to do
The same kinds of questions that work for text documents work for PDFs:
- Summarisation — "Summarise this 40-page contract in three paragraphs."
- Question answering — "What is the termination notice period?"
- Extraction — "List all the dates mentioned in this document with their associated events."
- Analysis — "Which sections of this document mention intellectual property?"
- Comparison — with multiple PDF blocks in the same message, "What are the differences between Contract A and Contract B?"
- Structured output — "Return a JSON object with the key clauses as fields."
Combine PDF support with the prefill + stop_sequence pattern from Module 3 and you have a reliable structured-data extraction pipeline for contracts, forms, and reports.
A practical note on size and token cost
PDFs translate into a lot of tokens. A 50-page document with dense text can run into tens of thousands of tokens just for the input. Two practical consequences:
- Check the size before sending. Prefer the smallest version of the document that contains what you need. For a 200-page manual where you only care about chapter 3, extract the chapter first.
- Consider RAG for large corpora. If you're doing retrieval across many large PDFs, the pattern from Module 7 (chunk, embed, retrieve) is usually better than stuffing whole PDFs into every prompt. Use PDF support for one-shot document analysis; use RAG for repeated querying against a library.
For a single document you actually want Claude to read end to end, PDF support is the right tool. For a knowledge base of hundreds of PDFs where each query only needs a section from one of them, build a RAG pipeline that chunks the PDFs and retrieves relevant passages.
One-line summary
If you already understand image support, PDF support is essentially free — change the type to "document", change the media_type to "application/pdf", and the rest of your code is the same. What you gain is a direct path to document-level analysis without any parsing infrastructure of your own.
Key Takeaways
- 1PDF support uses the same message block structure as image support, with type set to 'document' and media_type set to 'application/pdf'.
- 2Claude extracts text, embedded images and charts, tables, and document structure from PDFs, replacing a multi-library document-processing stack with a single API call.
- 3Everything you can do with text documents — summarisation, Q&A, extraction, analysis, comparison — works on PDFs directly, including structured output via prefill + stop_sequence.
- 4PDFs use a lot of tokens; prefer the smallest version of the document that contains what you need and consider extracting just the relevant section before sending.
- 5Use direct PDF support for one-shot document analysis; use RAG for repeated querying across many large PDFs where each query only needs a small subset.