4 Replies Latest reply on Jun 6, 2009 4:57 AM by ab1301

    Reading text fields values from PDF programmatically in AIR

    Ali_Rizvi_

      I want to load a filled in PDF file in my AIR application and extract what fields are there and their values.

      I have searched in many places but haven't found a solution yet.

      One suggestion that I found is to put javascript in the PDF file from before and then invoke that javascript from my AIR app to get the information needed. But I have to work with PDF files not authored by me.

       

      Is it possible to achieve this?

       

      Thanks,

      Ali.

        • 1. Re: Reading text fields values from PDF programmatically in AIR
          Jeff Swartz Level 3

          In order for AIR to interact with PDF content, the PDF file needs to include JavaScript. So, in general, no you cannot obtain form data from any arbitrary PDF file.

          • 2. Re: Reading text fields values from PDF programmatically in AIR
            ab1301 Level 1

            I know that when you are dealing with html in air, you can basically write all of your javascript in the actionscript of your flex app, by creating an object variable that represents the dom (usually the variable name is "dom").  Any javascript function or variable can then be accessed like this: dom.javascriptvariable or dom.javascripfunction().  It's called "cross-scripting."  I would be very surprised if you could not also "cross-script" with the javascript in pdf content as well (this would mean that the pdf does not have to have any javascript, you should be able to write all of the javascript in actionscript in your air app).  Do some searches with "cross-scripting", "pdf", and "flex" or "actionscript" and you will probably find what you're looking for.

            • 3. Re: Reading text fields values from PDF programmatically in AIR
              Jeff Swartz Level 3

              You cannot dynamically add JavaScript into a loaded PDF file in AIR.

               

              ab1301 is correct: ActionScript in Flex can add properties and functions to the window object of a loaded HTML page (using cross-scripting). But you cannot do the same sort of thing with PDF content.

              • 4. Re: Reading text fields values from PDF programmatically in AIR
                ab1301 Level 1

                Unfortunately, as far as i can tell, Jeff is right.

                 

                The solution would be to have a folder level javascript file in your acrobat app directory, and use the messaging system described here:

                http://www.adobe.com/devnet/air/flex/quickstart/scripting_pdf.html

                 

                But the javascript in the example won't work in folder level javascript because there is no way (that I can find) to access the document object from a folder level script (in the example, and in any document level script, "this" refers to the document object, while in a folder level script "this" is undefined).  Accordingly, it is impossible to define the host container (since host container is defined by reference to the document object), making it impossible to listen for messages from the host container.

                 

                I could be wrong, but from what I can tell any method that returns a document object throws a security error or returns undefined when called from a folder level script.  This is very annoying and limiting, but so are a lot of security features.

                 

                One way you might be able to get around this depending on what you are trying to do is to use a batch script to add your document level script to all of your pdf documents.  Of course this does nothing to allow immediate interaction with pdfs as you download them from the internet.  (Plus, I am not certain this is even possible.  Just an idea.)