Guide
How to rename PDF files based on what is inside them
You have a folder of files called scan0043.pdf and you want them called Thompson Steel INV-52445.pdf instead. Here are the ways to do that, cheapest first.
Short answer
If the PDFs have a text layer, a short PowerShell or Python script does it for free. If they are scans, you need something that can read an image. If the layout varies between suppliers, you need something that understands the document rather than matching a position.
First, check whether your PDFs have text in them
This one question decides which methods will work, and almost every guide skips it.
Open one of the files and try to select a line of text with your mouse. If you can highlight it, the file has a text layer and the cheap methods below will work. If your cursor just drags a box over a picture, it is a scan, and anything that reads text will fail on it.
A folder usually contains both. Anything emailed to you as a PDF normally has text. Anything that came off a scanner or a phone camera normally does not.
Method 1: a script, if the text is selectable and always in the same place
This is free and it is the right answer for a lot of people. If every invoice comes from one supplier, the invoice number sits in the same spot on every file, and you can grab it with about fifteen lines of Python.
- 1Install Python from python.org, and then run: pip install pymupdf
- 2Write a script that opens each PDF, pulls its text, finds the value with a regular expression such as INV-\d+, and renames the file.
- 3Run it on a copy of the folder first, never the originals.
Free and fast, and it will serve you for years if your documents are consistent. It falls apart the moment a second supplier with a different layout appears, because a regular expression matches a pattern, not a meaning.
Method 2: Adobe Acrobat Pro, if you already pay for it
Acrobat Pro has an Action Wizard, and there are paid plug-ins such as AutoSplit and Evermap's AutoRename that rename using text found on the page.
You define where to look, typically by searching for a label like "Invoice No" and taking what follows it.
Sensible if Acrobat is already on your machine. Not worth buying Acrobat for, and the plug-ins are a separate purchase on top.
Method 3: a dedicated renaming tool
Several Windows tools exist specifically for this: Win2PDF Pro, File Juggler, and Gillmeister's Automatic PDF Processor among them. Most work by watching a folder and applying rules you define.
They are mature, they are cheap, and if your documents are regular they will do the job.
The right answer for a predictable, high volume flow. You do have to sit down and define the rules, and that is the part most people never get around to.
Method 4: something that reads the document
The three methods above all need you to describe where the value is. That works until the tenth supplier uses a different word for the same thing, calls it Ref instead of Invoice No, or puts the total on the second page.
The newer approach is to have the document read rather than pattern matched, so the rule becomes "the supplier's own reference, wherever it appears" instead of "the text 40mm from the top edge".
This handles scans as well, because a picture can be read the same way a page of text can.
Worth it when your folder has many different senders in it. Overkill when everything comes from one place in one format.
Whichever you pick, do these two things
- Run it on a copy
- Duplicate the folder and test there. A renaming pass that goes wrong across four hundred files is very hard to reverse by hand.
- Decide what happens on a clash
- Two invoices with the same number will collide. Good tools add a suffix. Bad ones overwrite, and you lose a file without being told.
Common questions
- Can Windows rename files based on their contents?
- No. File Explorer can rename in bulk, but only using the existing name, a number, or a date. It cannot look inside the file. Anything that reads the contents needs a script or a separate tool.
- Will this work on scanned documents?
- Only if the method can read a picture. Scripts and most rule based tools read the text layer, which a scan does not have. You either need OCR software first, or a tool that reads the image directly.
- What is the free way to do this?
- A Python script with PyMuPDF, if your PDFs have selectable text and the value you want is findable with a pattern. That covers a lot of cases and costs nothing but an afternoon.
Related
- Renaming scanned documents that have no text
- Getting invoice data into a spreadsheet
- Once, our free tool for this
Solven builds custom software and automation for Australian businesses. If you have a job like this that no tool quite fits, that is the work we do.
Get a free teardown