Convert a PDF file into CSV, Excel or Numbers format using Applescript

854 views Asked by At

Every month I get my bank balance which it is basically just a table. In order to get a better overview of my expenses I would like to export this list into a Numbers (iWork) document. My wish would like to use Applescript so can automate this process :)

Does anyone knows how can I convert a PDF (text-type) list into CSV, Excel or Numbers?

1

There are 1 answers

0
CRGreen On BEST ANSWER

If you've tried any code, it would be good to see. Also, it's hard to know what the results might be without seeing how the type of pdf you're working with goes through this kind of process. With that in mind, here's the kind of process I'm talking about...

I would suggest downloading and using the beautifully script-able Skim pdf app (http://skim-app.sourceforge.net/). Preview is too limited. The basic Adobe reader probably has adequate functionality, but, well, I'm a Skim fan. A CSV file is basically just text, so this should work, but again, not knowing how your text is formatted I cannot be sure of the results. I'd be happy to make edits if you share examples. The following worked well with a pure text pdf:

tell application "Finder" to set dt to desktop as string
tell application "Skim"
    set docName to name of document 1
    set baseName to text 1 thru ((offset of "." in docName) - 1) of docName
    set docText to text of document 1
    set filePath to (dt & baseName & ".csv")
    set myFile to open for access filePath with write permission
    write docText to myFile --as «class utf8»--depending on results, you may need this last part. test
    close access myFile
end tell
tell application "Numbers"
    activate -- I got weird buggy results not activating (or at least launching) first.
    open alias filePath
end tell