Free

Free coded apps to suit all. No sign up, no email, usable offline, updates when I can, feedback welcome. Send feedback

Thinking

Is there a command line tool for PDFs?

Yes. PDF by Zaweba has a command line: --inspect reports on a file, --render draws a page as a picture and --extract-text pulls out the text, offline.

Is there a command line tool for PDFs?

There is. The program behind PDF by Zaweba can be run from a command prompt with three jobs: --inspect reports on a file, --render draws a page as a picture, and --extract-text pulls the text out. It runs offline on Windows, so it fits into scripts and scheduled tasks without sending anything anywhere.

A command line is handy when the same small job has to be done many times, or when another program needs to call on a PDF tool without anyone clicking through windows. A script that checks every PDF in a folder, or makes a preview picture of each first page, is a few lines once the tool is there.

The three commands

Inspect gives a report on a PDF. Type ZawebaPDF.exe --inspect file.pdf and it tells you about the file; add --json and the report comes out as JSON, which is much easier for another script to read.

Render draws a page as an image. ZawebaPDF.exe --render file.pdf --page 3 --dpi 150 --out page.png draws the third page at 150 dots per inch and saves it as page.png. Change the page number and the resolution to suit: a low number for small previews, a higher one for something to print or study closely.

Extract text pulls the words out. ZawebaPDF.exe --extract-text file.pdf gives the text of the whole file; --pages 1-3,7 limits it to those pages, and --out text.txt saves it to a file instead of showing it.

For protected files, --password supplies the password. And --cli-help lists all of the options, which is the place to look when you forget one.

Using it in a script

Exit codes make scripting reliable. The program returns 0 when it has done the job, 1 when it failed, 2 when the arguments were wrong, and 3 when a password is needed or the one given is wrong. A batch file or PowerShell script can check that number and decide what to do next, such as logging the files that need a password and moving on.

A few uses that suit it well: pulling the text out of a folder of reports so another program can search them, making a thumbnail of the first page of each new PDF for a catalogue, or running --inspect --json over incoming files to spot ones that need attention before anyone opens them.

Avoiding common slips

Text extraction only finds real text. A scanned page is a picture, so --extract-text returns little or nothing from it. Run OCR on scans in the app first, then the command line can read them.

Pick the resolution with care when rendering. Large numbers make large pictures and take longer, so for a folder of previews keep it modest.

Put paths in quotes when they contain spaces, as with any Windows command. It's the most common reason for a wrong-arguments exit code.

Command line or Actions?

The command line covers inspecting, rendering and extracting text. For bigger jobs such as reducing size, redacting, protecting or flattening many files, Tools > Actions in the app does those as saved lists of steps, and watched folders can run them as files arrive. Many people use both: Actions for the heavy work, the command line for a quick report or a page preview inside a script.

So if you want PDF work in a script, PDF by Zaweba gives you a free, offline command line with clear exit codes to build on.