- Extract and query PDF content with local AI.
- Request summaries, tables, and answers with page references.
- Reuse the RAG technique you already know in a new use case.
Key concepts
Here we apply the same approach as the legal chatbot: RAG (search your documents and answer with those snippets). What's new is that a PDF isn't always clean text.
Step by step
Create the project and start Claude Code:
cd ~/proyectos-ia mkdir pregunta-pdf cd pregunta-pdf claude
Paste this prompt:
Run on your computer
npm install npm run dev
Open the local address, upload a PDF, and ask something specific you know is in the document.
A guided end-to-end test
To verify everything works without relying on your own files, use a public PDF from the BOE. Download the Spanish Constitution (public domain) and place it in your project's docs/ folder:
mkdir -p docs curl -L -o docs/constitucion.pdf \ "https://www.boe.es/buscar/pdf/1978/BOE-A-1978-31229-consolidado.pdf" npm run dev
Open the app, upload (or reindex) constitucion.pdf and type this exact question:
What you should see: an answer that cites Article 14 and mentions that Spaniards are equal before the law, without discrimination on grounds of birth, race, sex, religion, opinion, or any other personal or social condition. The app should show the file ( constitucion.pdf ) and a page number. If it responds with made-up content or without a citation, reindex the PDF and ask again.
If something goes wrong
- Empty text when indexing — scanned PDF: enable OCR.
- Slow responses — normal for long documents; try a smaller model or reduce how many snippets it uses per answer.
- Cites the wrong page — ask Claude Code to use smaller chunks when indexing.
Practice challenge
Ask Claude Code to add a "compare two PDFs" mode (for example, two versions of a contract) and highlight the important differences.