Convert PDFs to Text Locally with Llama-Scan and Ollama
Job to be done: Convert PDFs to text files locally using LLMs
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
Convert your CSC201 lecture slides or a research paper PDF into text to easily search for definitions, extract quotes for an assignment, or create flashcards for exam revision, all offline.
- 9-5 employee
Convert a lengthy PDF policy document or client proposal into text to quickly search for specific terms, extract key points for a summary report, or prepare for a presentation, ensuring data privacy.
- Entrepreneur
Extract key clauses from a PDF contract or a market research report into plain text for quick analysis, without uploading sensitive documents online or incurring recurring fees.
What you’ll get
You will convert any PDF document (including those with images and diagrams) into a plain text file on your own computer. This approach uses local AI models, meaning you don’t need an internet connection after the initial setup, and there are no ongoing costs or ‘token’ fees.
Tools you need
- Python (free): The programming language needed to run the
llama-scantool. - Ollama (free): A tool that lets you run large language models (LLMs) directly on your computer.
- llama-scan (free): A Python tool that uses Ollama to read and convert PDFs into text.
Steps
-
Install Python: First, you need Python 3.10 or newer. If you don’t have it, download and install it from the official Python website (python.org). On Windows, make sure to check the box that says “Add Python to PATH” during installation.
-
Install Ollama and download the model: Ollama is a tool that lets you run powerful AI models directly on your computer. Go to the Ollama website (ollama.com) and download the installer for your operating system (Windows, macOS, or Linux). Follow the installation instructions. Once installed, Ollama will run in the background.
Next, open your computer’s terminal (on Windows, search for ‘Command Prompt’ or ‘PowerShell’; on macOS/Linux, search for ‘Terminal’). Type this command and press Enter to download the
qwen2.5vlmodel. This model can understand both text and images.ollama run qwen2.5vl:latestYou will see a download progress. This might take some time depending on your internet speed. Once it’s done, the model will be ready to use. You can then type
/byeand press Enter to exit the chat, or simply close the terminal window. -
Install llama-scan: In the same terminal window (or a new one), type this command to install the
llama-scantool:pip install llama-scanYou should see messages about
llama-scanand its dependencies being installed. If it finishes without errors, it’s ready. -
Prepare your PDF file: Make sure you have the PDF file you want to convert saved on your computer. Note down its full path (e.g.,
C:\Users\YourName\Documents\my_report.pdfon Windows, or/Users/YourName/Documents/my_report.pdfon macOS/Linux). Remember to use double quotes around paths that contain spaces. -
Convert the PDF to text: In your terminal, use the
llama-scancommand followed by the full path to your PDF file. For example:# Windows (Command Prompt or PowerShell) llama-scan "C:\Users\YourName\Documents\my_report.pdf"# macOS or Linux llama-scan "/Users/YourName/Documents/my_report.pdf"By default,
llama-scanwill create a new folder calledoutputin the same location where you run the command. Inside this folder, you will find a text file (.txt) containing the content of your PDF.Optional: Specify an output folder: If you want the text file to be saved somewhere else, use the
--outputoption:# Windows (Command Prompt or PowerShell) llama-scan "C:\Users\YourName\Documents\my_report.pdf" --output "C:\MyTextFiles"# macOS or Linux llama-scan "/Users/YourName/Documents/my_report.pdf" --output "/home/YourName/MyTextFiles"Optional: Convert specific pages: To convert only a part of the PDF, use
--startand--end:# Example: Convert pages 1 to 5 llama-scan "document.pdf" --start 1 --end 5You will see messages in the terminal as
llama-scanprocesses each page. Once it’s done, check your specified output folder (or the defaultoutputfolder) for the new text file.
Original source
This workflow was created by nawazgafar and shared on Hackernews. It uses the open-source llama-scan tool to process PDFs with local AI models.
Notes & variations
- Common mistake: The most common issue is not having Ollama running in the background or not having the
qwen2.5vl:latestmodel downloaded. Make sure Ollama is installed and the model download step is completed successfully before runningllama-scan. - Tip for better results: For complex PDFs, you can provide custom instructions to the model. Create a text file (e.g.,
instructions.txt) with specific guidance (e.g., “Summarize each section” or “Extract only the financial figures”). Then, use the--custom-instructionsoption:llama-scan your_file.pdf --custom-instructions instructions.txt. - Alternative models: The
llama-scantool allows you to use other multimodal models supported by Ollama. You can find a list of available models on the Ollama website. To use a different model, replaceqwen2.5vl:latestwith your chosen model name in theollama runcommand and thellama-scancommand (using the--modeloption).