8 Replies Latest reply: Dec 24, 2010 4:40 AM by khkremer RSS

    getchar() and putchar() in adobe javascript

    FrancisFukuyama Community Member

      One of the simplest programs that are written in C for newbies is pure input  and output of characters from pressed keys in succession (with some max  repetition allowed by the operating system settings for key pressed for extended  period).

       

      #include <stdio.h>

      main(){

      int c;

      while ( (c=getchar()) != EOF)

           putchar(c);

      }

       

      I want to write a similar minimal program in acrobat  javascript.

       

      The script may be document/application level ... most preferably not attached  to any specific field on any page and listens for the Keystroke ... ie a pressed  key.

       

      However, if it MUST be attached to a field ... then that field would be a  button field which is on the current page and in focus ... but this will take  away the simplicity I desire and as exhibited in the C program above which  compiles and works.

       

      I want to print the letter corresponding to the key pressed on the console  using this statement or another ...

       

      console.println(c);

       

      [QUESTION] How do I read the key pressed ?

       

      Thanks,

      Francis Fukuyama

       

       

      as a newbie i did lots of search in the sdk and guide before asking this  question.

       

      i need acrobat to do events globally irrespective of page based on what key  is pressed in certain contexts so it should not interfere with other normal  operations.

       

      alternatively, i need three of four modifiers of mouse events but  nothing is more convenient on the fingers than pressing a key like y/n for  yes/no .

       

      Are there any non-reserved keys or non-reserved clicks events that can be  recorded at the global, application or document level, or else be intercepted by  a button and then recorded in some kind of file or hidden field for that button  and then automatically "recorded or downloaded" into a text file as a data ?

       

      Thanks again for any help.

      Francis

       

       

      1,505 posts since 
      Aug 11, 2002
      2. Dec 17,  2010 11:03 PM in response to: FrancisFukuyama
      Re: getchar() and putchar() in adobe  javascript

      You would have to create a custom plug-in to have any hope of accomplishing  this. JavaScript cannot do what you describe. You might want to pose this  question in the Acrobat SDK forum here if you haven't already.

       

       

        • 1. Re: getchar() and putchar() in adobe javascript
          FrancisFukuyama Community Member

          no reply for so many days ...

           

          is this forum dead ????

           

          Francis Fukuyama

          • 2. Re: getchar() and putchar() in adobe javascript
            lrosenth Adobe Employee

            There are no file system APIs (such as get/putchar) in Acrobat JavaScript due to security concerns.

             

            It sounds like you really need a custom plugin (in C/C++) in order to intercept keys/events as you wish.

            • 3. Re: getchar() and putchar() in adobe javascript
              FrancisFukuyama Community Member

              I have explained my goal and i want to know how to go about

              intercepting key presses etc. and when the mode is turned on, it

              interprets 2 or 3 keys differently.

               

              Pleez suggest solution details.

              • 4. Re: getchar() and putchar() in adobe javascript
                lrosenth Adobe Employee

                If you only want to do this in form fields, you can use JavaScript as described in the JavaScript docs.

                 

                If you want to do this at any time, then you need to write a custom plugin in C/C++ as described in the Acrobat SDK documentation.

                • 5. Re: getchar() and putchar() in adobe javascript
                  FrancisFukuyama Community Member

                  Dear Irosenth, thanks for giving me some attention.

                   

                  I want to "do this at any time" and therefore I have to write a custom

                  plugin in C/C++ . But the doc is huge pdf ~ 6000 pgs and slows down my

                  pc a lot as I make any bookmark it takes 2 minutes to save the file

                  (so much for the size independence of the xref table scheme ...

                  actually i dont know where the issue is as the PC is fast with other

                  huge files except the ones by adobe and there are no images and its a

                  vector pdf ). So learning by searching around is quite difficult due

                  to slow speed and learning by linear study (6000pgs) is not easy. I

                  would like to get started by a simple starter script that I can

                  compile and then search for its functions and some guide to reading so

                  that I can then help myself.

                   

                  I appreciate your kind help a lot.

                   

                  Francis Fukuyama

                  • 6. Re: getchar() and putchar() in adobe javascript
                    lrosenth Adobe Employee

                    The SDK comes with a LOT of sample code for plugins.  Also, are you reading the PDF reference/ISO 32000 or the documentation for writing plugins?

                    • 7. Re: getchar() and putchar() in adobe javascript
                      FrancisFukuyama Community Member

                      a

                      Dear Irosenth,

                       

                      The two docs are these:

                       

                      acrobat_pdfl_api_reference.pdf

                       

                      plugin_apps_developer_guide.pdf

                       

                      I am a newbie so i dont even know what in your colloquialism you mean by

                      "PDF reference/ISO 32000" .

                       

                      The fact that the documentation is huge means I need some guidance for going

                      to relevant portions. I assume that the documentation is NOT SUFFICIENT by

                      itself or there would be no need of forums in addition.

                       

                      *I have specified how I think I might be helped and it is by some working

                      small example relevant to my problem and some guided reading so that I can

                      then look up doc on the functions used in that example.*


                      *I work in C/C++ and can get the gnu compiler for windows to make an

                      executable.*

                       

                      Regards,

                      Francis Fukuyama

                      • 8. Re: getchar() and putchar() in adobe javascript
                        khkremer CommunityMVP

                        Francis,

                         

                        The SDK documentation is sufficient, I learned plugin development just from reading all the relevant documents. The SDK comes with sample plugins that you can use to start your own project.

                         

                        However, your development environment will not be sufficient to develop Acrobat plugins: you need Visual Studio on Windows and XCode on the Mac. Which version is necessary depends on which version of the SDK you are using.

                         

                        The PDF reference is the document that describes The PDF file format, and is necessary if you want to access information in a PDF, add to, or modify a PDF. Since the PDF format is no longer owned by Adobe, but is now an international standard, that document is available as ISO32000 through ISO, but you can still find the previous version on Adobe's web site.

                         

                        Plugin development is complicated, don't expect to learn it in an afternoon or a week or even a month.

                         

                        Karl Heinz Kremer

                        KHKonsulting LLC

                        PDF Acrobatics Without a Net

                         

                        khk@khk.net

                        http://khkonsulting.com