Moderator's Note 2022/11/19 14:09 CST:
Carsten Blüm's version of pdftotext is no longer available, but you can find a working version here.
See this section:
- Download the Xpdf command line tools:
- Mac 64-bit: download (GPG signature)
Hey John,
If you were on 10.10.x it would be fairly easy with ASObjC.
Since you're on 10.9.x I'd install this little Unix executable:
http://www.bluem.net/files/pdftotext.dmg?rev=0
The package installs it here:
/usr/local/bin/pdftotext
Invoke it in an Execute Shell Script action like this:
/usr/local/bin/pdftotext -layout -
Note the dash at the end — this is vital, because it caused the output to to go StdOUT instead of a file.
A working example on my system:
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;
pdftotext -layout "/Users/chris/test_directory/pdf_test_files/test.pdf" -
Turning it into an AppleScript that works on the selected file:
tell application "Finder" to set finderSelectionList to selection as alias list
if finderSelectionList ≠ {} then
set posixFilePath to POSIX path of (first item of finderSelectionList)
set shCMD to text 2 thru -2 of ("
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;
pdftotext -layout " & (quoted form of posixFilePath) & " -
")
set pdfText to do shell script shCMD
end if
You can see what the output looks like by running this in the Terminal:
pdftotext -layout -
Make sure the trailing dash is on the end of the command, and run it.
-Chris