Re: PDF Form Reading
Re: PDF Form Reading
- Subject: Re: PDF Form Reading
- From: Rob Stott <email@hidden>
- Date: Fri, 21 Jan 2005 09:36:36 +0000
On 21 Jan 2005, at 05:25, Bruce Robertson wrote:
Is it possible with Smile or other tools to read data from filled-in PDF
forms?
Hi Bruce,
There's probably a much more elegant way of doing this, but here's how I go about it. Note, my JavaScript is a bit shaky so I tidy up my results in AppleScript afterwards. Crikey, how I WISH we had all that Acrobat JavaScript functionality in AppleScript *sob*;
set theFieldList to {}
tell application "Adobe Acrobat 7.0 Profe#5D2"
tell front document
--I'm assuming there is already a document open, with some form fields
--get the field contents and names using a JavaScript - note that this tends to error if the document is minimised
activate
set theContents to every paragraph of (do script "var theResponse = \"\"; for (var i = 0; i < this.numFields; i++) {var theFieldName = this.getNthFieldName(i); var theField = this.getField (theFieldName); var theResponse = theResponse + (theFieldName + \"\\t\" + (theField.value)+ \"\\r\");}; theResponse;")
end tell
end tell
--put the retrieved data into a useful list
repeat with theRecord in theContents
set AppleScript's text item delimiters to " "
set theFieldName to text item 1 of theRecord
try
set theFieldContents to text item 2 of theRecord
on error
--note that blank fields will cause an error, in the event of a blank field, the field contents is set to ""
set theFieldContents to ""
end try
set theFieldList to theFieldList & {{theFieldName, theFieldContents}}
end repeat
--trim off the messy last record
set theFieldList to items 1 through (the (count of the items of theFieldList) - 1) of theFieldList
The above example tends to freak out with some foreign characters, eg Greek, Russian but works fine for English and Western European characters - not sure why this is, maybe someone could offer an explanation/solution? An alternative method that you might like to have a look at is exporting an XFDF from the PDF and parsing that.
Hope that's of some help,
Regards
Rob
---
Rob Stott - Development Team, Trident UK
Work: +44 (0) 1482 887212 • Mobile: +44 (0) 7881 811533 • Home: +44 (0) 1482 671129
My work: http://www.apple.com/uk/creative/trident/
My band: http://www.superscapemusic.co.uk
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden