Skip to main content
Known Participant
March 13, 2020
Answered

Javascript coding within a PDF document

  • March 13, 2020
  • 1 reply
  • 3724 views

Good morning,
I've been searching everywhere for a specific set of codes that I can't seem to find. Here's in a nutshell the situation since I don't even know if this is possible:
I have a PDF form that I created with tons of buttons on it for extra information on each field. In other words, when pressed it shows instructions related to that specific field. I have to create that form in a bilingual way and therefore the instructions have to also be bilingual. I though the easiest way to do this without crowding the text box display would be the following:
1- when the information bubble is press, the button would trigger a display that would ask to press English or French.
2- if English is pressed then the English text would display and if French is pressed then the French text only would display.
3- after displaying the text, it would have the usual OK button to close the information text and return to the form.
I managed to create button tool to display the entire text in English and French all at once, but then realized it it way to long and in some cases you can't even see the OK button to get out of it, that's why I thought separating the text would work better, but I have no clue how to create the display to chose FRENCH or ENGLISH selection. Or even better, to display by default the English one with an option at the bottom that would say "Press here for French" "Press OK to return to the form".

    This topic has been closed for replies.
    Correct answer Thom Parker

    You have several options for displaying text, an alert, a hidden form field, or, you could put the lanuage text directly into the menu, so you don't have to handle the return value. This is the easiest for both you and the user, as long as the text entries are short.

     

    app.popUpMenu(["English", "England is a great country"], ["Français", "La France est un grand pays"]);

    1 reply

    Thom Parker
    Community Expert
    Community Expert
    March 13, 2020

    It would be good to have a method at the document level for determining language. For example, radio buttons at the top of the first page. 

     

    However if you want the user to make a selection at the time they display the message, then a couple of good options are a popup dialog box or a  popup menu. I like menus. 

    https://www.pdfscripting.com/public/Creating-Popup-Menus.cfm

     

    You may want this popup to only appear the first time, that way it's not a constant annoyance. Use a document level variable to determine whether or not the popup language selection is displayed.

     

     

     

     

     

    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
    Known Participant
    March 15, 2020

    Thank you for this information, it's a real eye oppener on the world of creating menus.

    It's definitely in the right direction of what I want to do and as much as it's interesting to see the possibility of creating a menu when the user presses a button, the programmation explained on that page is a bit confusing for me as I'm a beginner with javascript coding and most terms they use they assume that we know what they should be, so I'm still lost into how to proceed after creating a menu.

    Here's an example, when they showed how to use the Return Value, I thought that was what I needed for sure, since I want for the user to select either French or English and then according to their selection, a text in the language they select would appear, but I still don't understand how the menu and text to appear are programmed together?

    I can't have the menu just once, it's how the form will be designed as a bilingual written all the way through the form, I want to have each time they select an information bubble for each field, to have an option on each field to ask if they want the English or French text and then to have the proper text poping up to them after the selection.

    It would be great if you could show me an example on how to accomplish that.  Here's an example of the interaction: there's a field asking them to select a level of security, they don't understand what that implies, so they select the information bubble (button) to have more information, when selecting that button, a menu would appear showing them two options "French" or "English", then if they select French, a text would appear to say "France is a great country" or if they select English, a text would appear to say "England is a great country" and after reading the text, it would have a box at the bottom to click OK to return to the form.

    All those answer text are right now programmed in the form into a javascript using "app.alert" command and they work fine, but I wanted to seperate English from French for display space saving.

    Javascript options are great, but it gets very complicated if someone like me just start using them 😉  Never the less to say that I really like your menu option and would love to use it if I can only understand how this would work with the return text.

    Thom Parker
    Community Expert
    Thom ParkerCommunity ExpertCorrect answer
    Community Expert
    March 15, 2020

    You have several options for displaying text, an alert, a hidden form field, or, you could put the lanuage text directly into the menu, so you don't have to handle the return value. This is the easiest for both you and the user, as long as the text entries are short.

     

    app.popUpMenu(["English", "England is a great country"], ["Français", "La France est un grand pays"]);

    Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often