Skip to main content
Known Participant
March 13, 2020
Answered

Javascript coding within a PDF document

  • March 13, 2020
  • 1 reply
  • 3713 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 17, 2020

    The coding used worked perfectly.  However, now I'm playing with the form to seek if I can do even better.  You mentioned previously that "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."  And I'm not disregarding that mention at all, in fact that's what I'm trying to work with right now to rise the form to a different level.  The problem I'm having at this moment is that each text box created on the multitude of fields on the form, are English/French within the same box to make the form functionnally bilingual for the user.  I'd prefer as you mentioned to have them select right from the beginning what language they'd like to use, but is that possible to have one form only and when they select English, then only the English text box would appear and vice versa?  Basically, I don't want to have two seperate forms, and both languages should be dormant in the background and when selected the proper one becomes active?  The problem right now is I can't see any possibility with a radio or any type of buttons, to activate/deactivate text boxes, it allows me to do that only on fields.  Is it even possible to have text boxes hiden or showing according to a selection on the PDF form?

    Known Participant
    March 18, 2020

    Here is a screen shot of the "Layers" panel on the left side of the Acrobat DC screen. 

    Notice there is a dropdown menu with an option for importing a layer. 

    Just try it out to start with. You'll see there is button in the layer's panel that you can use to turn the layer's on and off. 

    What you want to do for the form is create a blank PDF of the correct size, then import both PDF's that have the different languages.  Then use a script to hide or show a layer depending on language selection. 

     


    I never noticed that option before, mind you I never really used that side panel option lol

     

    Let's see if I get this straight before I start.  I'll create one layer of 5 pages in English and one layer of 5 pages in French and save them individually.  The part I'm not exactly sure about is the blank PDF of the correct size, when you say that, do you mean I create let's say a 3rd PDF which would have nothing but the fields and buttons I'd use and the layers to add to it would be the textual part in English and French?  Or do you mean in each layers I'll have everything, text, fields, buttons, graphic repeated in both the English and French layers?  I'm just not sure what you mean by the blank PDF of the correct size.

     

    No matter what, it starting to sound like a possibility if I hear this correctly and it may be the answers of what I'm trying to do.  Also, what would the script be for the button to activate/deactivate each layers?  And finally just to make this clear, once I bring both layers back, that means I wouldn't have to carry on with 3 different documents, it would be only one "core" with 2 layers within?

     

    BTW, in case I didn't mention this before, I really and definitely appreciate all your help with this, I'd be lost.