Keyboard Maestro “Convert PDF Files into Text Files in the Front Finder Window” Macro

Hey Folks,

I've posted a number of times in various threads about the Xpdf command-line tools – particularly about the pdftotext tool.

http://www.foolabs.com/xpdf/download.html

Look for the “x86, Mac” version in the “Precompiled binaries” section.

The the utilities contained in the Xpdf downloadable binary are:

pdfdetach
pdffonts
pdfimages
pdfinfo
pdftohtml
pdftopng
pdftoppm
pdftops
pdftotext

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

4 Likes

Chris,
I looked for the "Precompiled binaries" and don't see it. Is the above page still relevant? What I have are the files in the pic below. Is it safe to assume I can run make, make install?

Hey John,

Look in the bin64 folder. :wink:

-Chris

Also I recall you had me install this before so I checked for a man file and it appears I have xpdf (version 3.04) already installed. Can I just install over the top of my current installation?

I wasn't expecting a reply that fast. LOL!

2 Likes

So I tried the macro and nothing happens. When you say finder window, do I open the pdf in the front finder window or do I open the folder where the file is and select it? Neither seems to work.

Ok, never mind. It was added to the test group which was disabled. I got it to run.
I have a text file. It looks really good. I did get an error:

Shell Script
errorText:
xargs: unterminated quote

But since I have the text I need this will work.

Hey John,

This doesn't happen to me.

Send me a pic of the window you're running the macro on, so I can try to recreate the problem.

-Chris

Hey John,

Here's how to get the text of a single selected PDF file in the Finder into BBEdit.

** REQUIRES ** the same command line tool as the macro above.

-Chris


Finder -- Send Text of Selected PDF File to BBEdit.kmmacros (6.5 KB)

A couple of questions. Can I install v. 4.00 over my v. 3.04 version?

The install instructions say to copy xpdf, pdftotext, etc to /usr/local/bin I assume I can do:

cp /Users/zz/Downloads/xpdf-tools-mac-4.00/bin64/pdfdetach /usr/local/bin

Could I just do:

cp /Users/zz/Downloads/xpdf-tools-mac-4.00/bin64/* /usr/local/bin

I also seem to remember I had to do something to get it into my shell.

Hey John,

You don't need cp at all.

Just open a Finder window, type Cmd-Shift-G, and paste in the path you want to go to:

/usr/local/bin
/usr/local/man/man5

Then drag the requisite files into the correct folder.

The Finder will make you authenticate the action, but that's it.

Once you've copied the files you're good to go – UNLESS /usr/local/bin/is NOT in your $PATH.

You should not have a problem if pdftotext v3.0.4 was working for your, but if you do you can see this thread:

Create a PATH Environment Variable for Keyboard Maestro and Add /usr/local/bin to the Default Path

-Chris

I copied 4.0 version successfully, Thanks!

I put it into /usr/local/bin however the man folder appears to be missing from 'local'. Can I just create the folder(s)? (man, man5)

I am also wondering why it would be missing since I am obviously using man with other applications.

Hey John,

This sort of thing is easy enough to test yourself, but yes you can create those folders.

Because /usr/local/bin is a directory for USER-installed executables.

-Chris

Great tool!

1 Like

The script makes a txt file of every pdf in the current folder.
I would like to put the text of a (all) selected pdf file(s) into a KM variable.

How would the macro look like then? I know how to give the shell script a single file instead of a folder, but the shell script is expecting a folder and returns an error if i give it a single file instead.
How can i change this?

Hey @ccstone

A useful tool. Thank you very much for making it available!

1 Like