Gemini models can process documents in PDF format, using native vision to understand entire document contexts. This goes beyond just text extraction, allowing Gemini to:
- Analyze and interpret content, including text, images, diagrams, charts, and tables, even in long documents up to 1000 pages.
- Extract information into structured output formats.
- Summarize and answer questions based on both the visual and textual elements in a document.
- Transcribe document content (e.g. to HTML), preserving layouts and formatting, for use in downstream applications.
You can also pass non-PDF documents in the same way but Gemini will see them as normal text which will eliminate context like charts or formatting.
Passing PDF data inline
You can pass PDF data inline in the request. This is best suited for smaller documents or temporary processing where you don't need to reference the file in subsequent requests. We recommend using the Files API for larger documents that you need to refer to in multi-turn interactions to improve request latency and reduce bandwidth usage.
The following example shows you how to pass PDF data inline:
Python
from google import genai
import base64
client = genai.Client()
with open('path/to/document.pdf', 'rb') as f:
pdf_bytes = f.read()
interaction = client.interactions.create(
model="gemini-3.7-flash",
input=[
{
"type": "document",
"data": base64.b64encode(pdf_bytes).decode('utf-8'),
"mime_type": "application/pdf"
},
{"type": "text", "text": "Summarize this document"}
]
)
print(interaction.output_text)
JavaScript
import {