Edited 2022-08-21 to bring installation information up to date. -ccs
Hey Folks,
I've posted a number of times in various threads about the Xpdf command-line tools – particularly about the pdftotext
tool.
Look for the “Mac 64-bit” version in the “Download the Xpdf command line tools” section.
The utilities contained in the Xpdf downloadable binary are:
pdfdetach
pdffonts
pdfimages
pdfinfo
pdftohtml
pdftopng
pdftoppm
pdftops
pdftotext
Installation Instructions
Install the files in the bin64 folder here:
/usr/local/bin
Install the files in the doc folder here:
/usr/local/man/man5
The macOS hides these folders by default. To get there open a Finder window, type Cmd-Shift-G, and paste in the path you want to go to.
Then drag the requisite files into the correct folder.
If the necessary folders do not exist then create them. (The system will probably make you authenticate in order to do so.)
You may need to adjust your system PATH variable to use those folders, and keep in mind that doing so does NOT allow Keyboard Maestro see them. Keyboard Maestro has it's very own ENV_PATH
variable (create as needed), or you can simply specify full paths in individual shell scripts.
(Specifying full paths in shell scripts is generally a bad idea, as there are many circumstances under which those can change. It's usually a much better idea to use KM's ENV_PATH
variable.)
This macro uses the pdftotext
tool to convert PDF files in the Front Finder Window to Text files.
The macro is non-destructive – all text files are saved alongside their original PDF in the source directory.
Convert PDF Files into Text Files in the Front Finder Window.kmmacros (11 KB)
It is possible to route the converted text to STDOUT instead of to a file:
pdftotext -layout <POSIX_Path_of_Your_File> -
The trailing hyphen is ESSENTIAL.
I've done the heavy-lifting in the shell, but it is easy enough to iterate through the file list with a Keyboard Maestro For Each PathVar in a Directory action and apply the basic shell command to <PathVar>
instead.
-Chris