Skills.MD
# Gemini Document Processing
Process and analyze PDF documents using Google Gemini's native vision capabilities. Extract structured information, summarize content, answer questions, and understand complex documents with text, images, diagrams, charts, and tables.
## Core Capabilities
- **PDF Vision Processing**: Native understanding of PDFs up to 1,000 pages (258 tokens/page)
- **Multimodal Analysis**: Process text, images, diagrams, charts, and tables
- **Structured Extraction**: Output to JSON with schema validation
- **Document Q&A**: Answer questions based on document content
- **Summarization**: Generate summaries preserving context
- **Format Conversion**: Transcribe to HTML while preserving layout
## When to Use This Skill
Use this skill when you need to:
- Extract structured data from PDF documents (invoices, resumes, forms)
- Summarize long documents or reports
- Answer questions about PDF content
- Analyze documents with complex layouts, charts, or diagrams
- Convert PDFs to structured formats (JSON, HTML)
- Process multiple documents in batch
- Build document processing pipelines
## Quick Setup
### 1. API Key Configuration
The skill checks for `GEMINI_API_KEY` in this priority order:
1. Process environment variable
2. `.env` file in skill directory (`.claude/skills/gemini-document-processing/.env`)
3. `.env` file in project root
**Get your API key:** https://aistudio.google.com/apikey
**Option A: Environment Variable (Recommended)**
```bash
export GEMINI_API_KEY="your-api-key-here"
```
**Option B: Skill Directory**
```bash
cd .claude/skills/gemini-document-processing
echo "GEMINI_API_KEY=your-api-key-here" > .env
```
**Option C: Project Root**
```bash
echo "GEMINI_API_KEY=your-api-key-here" > .env
```
### 2. Install Dependencies
```bash
pip install google-genai python-dotenv
```
## Common Use Cases
### 1. Extract Structured Data from PDF
```python
# Use the provided script
python .claude/skills/gemini-document-processing/scripts/process-document.py \
--file invoice.pdf \
--prompt "Extract invoice details as JSON" \
--format json
```
### 2. Summarize Long Document
```python
# Process and summarize
python .claude/skills/gemini-document-processing/scripts/process-document.py \
--file report.pdf \
--prompt "Provide a concise executive summary"
```
### 3. Answer Questions About Document
```python
# Q&A on document content
python .claude/skills/gemini-document-processing/scripts/process-document.py \
--file contract.pdf \
--prompt "What are the key terms and conditions?"
```
### 4. Process with Python SDK
```python
from google import genai
client = genai.Client()
# Read PDF
with open('document.pdf', 'rb') as f:
pdf_data = f.read()
# Process document
response = client.models.generate_content(
model='gemini-2.5-flash',
contents=[
'Extract key information from this document',
genai.types.Part.from_bytes(
data=pdf_data,
mime_type='application/pdf'
)
]
)
print(response.text)
```
### 5. Structured Output with JSON Schema
```python
from google import genai
from pydantic import BaseModel
class InvoiceData(BaseModel):
invoice_number: str
date: str
total: float
vendor: str
client = genai.Client()
response = client.models.generate_content(
model='gemini-2.5-flash',
contents=[
'Extract invoice details',
genai.types.Part.from_bytes(
data=open('invoice.pdf', 'rb').read(),
mime_type='application/pdf'
)
],
config=genai.types.GenerateContentConfig(
response_mime_type='application/json',
response_schema=InvoiceData
)
)
invoice_data = InvoiceData.model_validate_json(response.text)
```
## Key Constraints
- **Format**: Only PDFs get vision processing (TXT, HTML, Markdown are text-only)
- **Size**: < 20MB use inline encoding, > 20MB use File API
- **Pages**: Max 1,000 pages per document
- **Storage**: File API stores for 48 hours only
- **Cost**: 258 tokens per page (fixed, regardless of content density)
## Performance Tips
1. **Use Inline Encoding** for PDFs < 20MB (simpler, single request)
2. **Use File API** for larger files or repeated queries (enables context caching)
3. **Place Prompt After PDF** for single-page documents
4. **Use Context Caching** when querying same PDF multiple times
5. **Process in Parallel** for multiple independent documents
6. **Use gemini-2.5-flash** for best price/performance ratio
## Decision Guide
```
PDF < 20MB?
├─ Yes → Use inline base64 encoding
└─ No → Use File API
Need structured JSON output?
├─ Yes → Define response_schema with Pydantic
└─ No → Get text response
Multiple queries on same PDF?
├─ Yes → Use File API + Context Caching
└─ No → Inline encoding is sufficient
```
## Script Reference
The skill includes a ready-to-use processing script:
```bash
# Basic usage
python scripts/process-document.py --file document.pdf --prompt "Your prompt"
# With JSON output
python scripts/process-document.py --file document.pdf --prompt "Extract data" --format json
# With File API (for large files)
python scripts/process-document.py --file large-document.pdf --prompt "Summarize" --use-file-api
# Multiple prompts
python scripts/process-document.py --file document.pdf --prompt "Question 1" --prompt "Question 2"
```
## References
For comprehensive documentation, see:
- `references/gemini-document-processing-report.md` - Complete API reference
- `references/quick-reference.md` - Quick lookup guide
- `references/code-examples.md` - Additional code patterns
## Troubleshooting
**API Key Not Found:**
```bash
# Check API key is set
./scripts/check-api-key.sh
```
**File Too Large:**
- Use File API for files > 20MB
- Add `--use-file-api` flag to the script
**Vision Not Working:**
- Ensure file is PDF format
- Other formats (TXT, HTML) don't support vision processing
## Support
- **API Documentation**: https://ai.google.dev/gemini-api/docs/document-processing
- **Get API Key**: https://aistudio.google.com/apikey
- **Model Info**: https://ai.google.dev/gemini-api/docs/models/gemini
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「gemini-document-processing」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次