Understanding Documents With Gemini
Gemini can process PDF documents using both their readable text and their visual page content.
This allows an application to work with more than plain extracted text. Gemini may also examine tables, charts, diagrams, images, headings, and the way information is arranged across a page.
A PDF is multimodal input
A PDF may contain written language, visual structure, images, tables, and diagrams. Gemini can consider those elements together while answering a question.
What Document Analysis Can Do
- Summarize a document
- Answer questions about its contents
- Extract action items
- Identify major sections and topics
- Compare information across pages
- Review tables, charts, and diagrams
- Locate names, dates, prices, or requirements
- Explain complex material in simpler language
Document analysis still requires verification
Gemini may misunderstand a table, overlook a qualification, confuse similar sections, or incorrectly interpret unclear scanned pages. Important findings must be compared with the original document.
Try the PDF Analyzer
Upload one PDF document and choose what Gemini should do with it.
Gemini PDF Analyzer
Upload one PDF and send it with an analysis instruction through the secure PHP endpoint.
Generated Analysis
How the Request Works
The browser sends the PDF and instruction to PHP using
multipart/form-data.
PHP then:
- Validates the course security token.
- Confirms that the upload completed.
- Checks the file size.
- Detects the actual MIME type.
- Checks for a PDF file signature.
- Reads the temporary document.
- Loads the Gemini key through AI-gency.
- Encodes the PDF as base64 data.
- Sends the instruction and PDF to Gemini.
- Returns only the generated analysis and safe metadata.
Do Not Trust the File Extension
A file named:
business-plan.pdf
is not automatically a valid PDF.
The endpoint checks both the detected MIME type and the opening PDF signature:
%PDF-
A filename is not validation
A user can rename any file. The server must inspect what was uploaded rather than trusting its visible name.
The Gemini Document Input
After validation, PHP builds this type of input:
{
"model": "gemini-3.5-flash",
"store": false,
"input": [
{
"type": "text",
"text": "Summarize this document."
},
{
"type": "document",
"data": "BASE64_ENCODED_PDF",
"mime_type": "application/pdf"
}
]
}
The text tells Gemini what to do. The document provides the information Gemini should examine.
Native PDF Understanding
A basic text extractor reads characters stored inside a PDF. That can be useful, but it may lose important visual context.
Native PDF processing can also help the model consider:
- Headings and page structure
- Tables and columns
- Charts and diagrams
- Images and captions
- Relationships between visual and written information
Scanned PDFs
Some PDFs contain selectable digital text. Others contain scanned page images.
Scanned documents may be harder to analyze when pages are:
- Blurry
- Crooked
- Low contrast
- Handwritten
- Partially hidden
- Extremely dense
A useful prompt should tell Gemini to identify any content it cannot read confidently.
Ask Focused Questions
This instruction is broad:
Tell me about this PDF.
This instruction gives the application a more useful task:
Review this proposal.
List the services being offered, every stated price, all deadlines,
the customer's responsibilities, and any cancellation terms.
Use a separate heading for each category.
Do not infer terms that are not written in the document.
Focused questions help determine:
- Which information matters
- How detailed the response should be
- How the response should be organized
- Which assumptions should be avoided
Long Documents
A model may technically accept a long PDF, but that does not make every broad request useful.
Instead of asking:
Explain everything in this 300-page document.
ask focused questions such as:
Identify the sections discussing pricing and payment terms.
Summarize the requirements described in chapters three and four.
List every deadline and the section where it appears.
Focused document analysis is easier to verify and usually produces more useful application output.
Inline Data Versus the Files API
Inline PDF Data
Best for a relatively small document used in one immediate request.
Files API
Better for larger files or documents that will be used in several requests.
This lesson uses inline data because the PDF is temporary, small, and analyzed only once.
Temporary Processing
The browser uploads the PDF into PHP's temporary upload location. The course reads it from that location and does not move it into a permanent public directory.
The PDF is still sent to the Gemini API for processing. Users should not upload documents they are not authorized to send to an external AI service.
Do not retain files without a reason
An application does not need to permanently save every file it processes. Temporary handling reduces unnecessary storage, exposed file URLs, and cleanup work.
Sensitive Documents
Avoid casually uploading documents containing:
- Passwords or API keys
- Financial account information
- Medical records
- Government identification
- Private customer records
- Confidential contracts
- Trade secrets or protected business information
A working upload feature does not automatically make every document appropriate to process.
Document Analysis Is Not Professional Advice
Gemini can help locate and organize information, but it should not replace qualified legal, financial, medical, or compliance review.
For high-stakes documents, use the analysis as a navigation aid and compare every important conclusion against the original PDF.
Practical Exercise
- Upload a small PDF you are permitted to process.
- Run the summary instruction.
- Review the input and output token usage.
- Ask one focused question about the document.
- Run the action-item instruction.
- Compare every important date, price, or requirement with the original PDF.
- Identify one detail Gemini handled correctly and one detail that required verification.
- Copy one generated analysis.
Completion goal
You should understand how a PDF upload is validated, encoded, combined with a text instruction, and processed as document input by Gemini.
Official Resources
Gemini Document Understanding Guide ↗
Lesson Summary
Gemini can analyze PDF documents using their written and visual content.
The browser uploads the PDF to PHP. PHP validates the file, confirms that it is a real PDF, reads it from temporary storage, encodes it, and sends it to Gemini as document input.
The API key stays on the server, the course does not permanently save the uploaded PDF, and the browser receives only the generated analysis and safe document metadata.