Professional Documents
Culture Documents
Enhancing Adobe Acrobat Forms With Javascript Take Your Forms To The Next Level 1St Edition Jennifer Harder Full Chapter
Enhancing Adobe Acrobat Forms With Javascript Take Your Forms To The Next Level 1St Edition Jennifer Harder Full Chapter
Standard Apress
Trademarked names, logos, and images may appear in this book. Rather
than use a trademark symbol with every occurrence of a trademarked
name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark. The use in this publication
of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of
opinion as to whether or not they are subject to proprietary rights.
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, express or implied, with respect to the material
contained herein or for any errors or omissions that may have been
made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
Note You can find the project files for the book at
www.apress.com/9781484228920.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub. For more detailed
information, please visit http://www.apress.com/source-code.
Acknowledgments
Because of their patience and advice, I would like to thank the following
people, for without them I could never have written this book:
My parents, for encouraging me to read large computer textbooks
that would one day inspire me to write my own books
My dad, for reviewing the first draft before I sent a proposal
My program coordinator, Raymond Chow, at Langara College, who
gave me the chance to teach evening courses and allowing me to find
new and creative ways to teach software
My various freelance clients who I have learned from and researched
more about forms and form layout through working on their projects
I would also like to thank Spandana Chatterjee and Mark Powers at
Apress for showing me how to lay out a professional textbook and
pointing out that even when you think you’ve written it all, there’s still
more to write. Also, thanks to the technical reviewer for providing
encouraging comments and to the rest of the Apress team for being
involved in the printing of this book and making my dream a reality
again. I am truly grateful and blessed.
Table of Contents
Part I: Basic Form Improvements
Chapter 1:A Fundamental Forms Primer
Forms Review
Fields Refresher
Properties Refresher
Text Box Field Properties and Date Field Properties Dialog
Boxes
Dropdown Properties Dialog Box
List Box Properties Dialog Box
Check Box Properties Dialog Box
Radio Button Properties Dialog Box
Button Properties and Image Properties Dialog Box
Digital Signature Properties Dialog Box
Barcode Properties Dialog Box
Tabs Refresher
Editing Your Form with the More Menu and Right Pane
Setting the Field Tab Order Using the Menu Options
Clearing a Form While Working
Summary
Chapter 2:Introduction to Actions
Getting Started
Rating Forms Value Averaging and Sum:Working with Text
Fields
The Validate Tab
The Calculate Tab for the Grand Total Using Sum
Sum and Averaging Using Check Boxes or Radio Buttons with
Text Fields
Using Radio Buttons on Page 3 of the Project
Using Check Boxes on Page 3 of the Project
Turning Check Boxes into Radio Buttons
Basic Action Button Triggers for Reset Buttons and Printing
Buttons
Reset Button
Print Form Button
Summary
Chapter 3:Creating a QR Code Custom Stamp
Customizing Your QR Code Stamp
QR Code Creation
Using the Stamp Tool
Final Thoughts:QR Code for Professional Printing
Summary
Chapter 4:Buttons, Navigation, Form, and Nonform Actions
Creating a Button Icon
Example of a Button as a Label Only
Example of a Button Combination of Icon Only
Nonform Properties Actions
Pages
Bookmarks
Web and Custom Hyperlinks
Rich Media Nonform Navigation Buttons
Layers Basic Actions
Other Nonform Actions That Can Affect Sticky Note or
Markup Tools Indirectly
Triggers for Actions
Choose an Action That Requires No Code
Newsletter Navigation with Buttons
Form Navigation with a Button as a Helpful Hint
Adding a Comb of Characters
Before Comb and After Comb
More Action Triggers to Show and Hide
Hide and Clear Fields Button
Set Layer Visibility
Using Bookmarks
Using Buttons
Summary
Part II: Simplified Field Notation and Basic JavaScript
Chapter 5:Introduction to Simplified Field Notation and JavaScript
Getting Started
Text Field, Date, and Drop-Down List Properties
Actions Tab
Format Tab
Validate Tab
Calculate Tab
Check Box, Radio Button, Image Field, and Button Properties
List Box Properties
Digital Signature Properties
Barcode Properties
Global Document JavaScript
Web Links and References
Regular Forms vs.E-Signature Forms
JavaScript and Acrobat on the Document Level
Summary
Chapter 6:Basic and Complex Calculations
Getting Started
Sum Value
Simplified Field Notation
JavaScript Custom Calculation Script
Final Thoughts on Working with the Calculate Tab
JavaScript Script Validation for Displaying Zero
The Final Line of Code
Drop-Down Alternatives
Set Field Calculation Order
Resetting Your Field of Focus
Summary
Chapter 7:Format Calculations
Number Formatting
Formatting with a Percentage
A Workaround for the Percentage
Reset Fields with JavaScript
Date Formatting
Date Formatting with JavaScript
Time Formatting
Time Formatting with JavaScript, a Custom Example
Comb of Characters for Dates
Special Formatting
Final Thoughts
Drop-Down Alternatives
More Information on Adding Decimal Places and Leading
Zeros
Summary
Chapter 8:Various JavaScript Alerts, Notes, and Time Stamps
Alert Types
Create a Document JavaScript
Viewer Version and Validation Alert
Document Actions
Document Will Close
Document Will Print
Alerts Working with Buttons
Adding a Comment Note, Signature, and Time Stamp
Signature Field and Time Stamp
Summary
Chapter 9:Create Help for Clients with Rollover Text and Alerts
The Rollover Method
Mouse Enter
Mouse Exit
Longer Array Example (Optional)
Extra Noncustom JavaScript Check Box Example
How to Show and Hide Fields with JavaScript
The Default Text Method
The Alert Method
Customer’s Full Name
Date
Customer Order Code
Customer’s Company Name
How to Duplicate Text for Multiple Fields and Make Fields
Read-Only
Set Fields to Read-Only with JavaScript
Final Thoughts
Summary
Chapter 10:Various Types of Formatting with JavaScript
Adding Global Formatting to Text Fields
Color Properties
Array and Variable Examples of Formatting Properties
Multiline Buttons
Multiline Text
Complex Formatting Using Check Boxes and a Text Field
Rich Text Formatting for Text Fields and Comments
Comment Example
Final Thoughts on Formatting with Text
Silent Printing
Options for Submit Button Using Email
Summary
Part III: Working with More Complex Forms
Chapter 11:Validation with Text Boxes, Alerts, and Radio Buttons
Money Transfer Example
Alternate Way to Work with Radio Buttons Without Alerts
Changing the Shipping Price Using Radio Buttons
Additional Radio Button Example with JavaScript and Text
Fields and How to Change Data for Time
Setting Up the Text Fields
Check Box Variation with Date Text Fields
Notes on Changing Formatting Options for Radio Button,
Check Box, and Button Style
Text Field Validation with Regular Expressions
Telephone Validation
Name Validation
Account Number Validation
Email and URL Validation
Another Phone and Date Example with Two Variables
Final Thoughts on Formatting Fields
Summary
Chapter 12:Working with Dropdown Lists
Current Skills Request Form
Parts Order Form
Drop-Down Lists with Select Dates and Discounts
Final Thoughts
Load a Lengthy Single Drop-Down or List Menu
Tips on Changing Custom Formatting for Drop-Down Lists
with JavaScript
Summary
Chapter 13:Working with List Boxes
List Box Priority List with Control Buttons
The Add Button
The Delete Button
The Clear or Reset Button
The Up Button
The Down Button
Check Box, Drop-Down, and List Box:Example 1
Check Box, List Box, and Multi-Drop-Down:Example 2
Button Slide Show Variation
Extra Example Priority List Improved
Final Thoughts
Hidden Fields
Using List Boxes for a Number Rating
Notes on Changing Custom Formatting for List Boxes
Summary
Chapter 14:Advanced Navigation:The Pop-Up Menu
The Pop-Up Menu Example
Add a Pop-Up Menu Using a Bookmark
Final Thoughts
Summary
Part IV: Beyond the Basics
Chapter 15:Action Wizard and JavaScript
Working with the Action Wizard
Reuse JavaScript from Chapter 8
Is It a Custom Action or a Custom Command?
Create and Manage Custom Commands
Summary
Chapter 16:Multistate Check Boxes
The Problem of Multistate Check Boxes
Bonus Star Rating Idea
Select All or Deselect All Check Boxes at Once
Summary
Chapter 17:Importing an Image into a Button
Creating the Button
Summary
Chapter 18:Multiple Formatting
The Problem of Multiple Formatting
Option 1:Do It Yourself
Price Script
No Price Script
Adding a Degree Symbol and Formatting Range
Option 2:Contact a Professional
Summary
Chapter 19:Digital Signatures and Barcodes
Digital Signatures and Security
Working with Digital Signatures and Other Adobe Security
Tools
Create a Security Puzzle
Barcodes
Summary
Chapter 20:What Are E-Signature Forms and Web Forms?
A Brief Look at Request E-Signatures and Resources
What Are Web Forms?
Summary
Part V: Putting It into Practice
Chapter 21:Homework Assignments
Homework Assignment 1:Show and Hide
Homework Assignment 2:Working with JavaScript to Create
Formulas
Area of a Circle A = π r 2
Field:CircumferenceRow1 Circumference of a Circle C =2 π
r
Field: VolumeRow1 Volume of a Sphere V = 4/3 π r3
Field:FahrenheitRow1 Celsius to Fahrenheit to Formula.(°C
x 9/5) + 32 =°F.
Field:CelsiusRow1_2 Fahrenheit to Celsius Formula.(°F -
32) x 5/9 =°C
Homework Assignment 3:Custom Validation and Regular
Expressions
Homework Assignment 4:Personal Drop-Down List Menu and
Definitions Text Box
Summary
Index
About the Author
Jennifer Harder
has worked in the graphic design
industry for more than 15 years. She has
a degree in graphic communications and
is currently teaching Adobe Acrobat and
Adobe Creative Cloud courses at Langara
College. She is the author of several
Apress books and related videos.
About the Technical Reviewer
Sourabh Mishra
is an entrepreneur, developer, speaker, author, corporate trainer, and
animator. His programming experience includes C/C++, ASP.NET, C#, VB
.NET, WCF, SQL Server, Entity Framework, MVC, Web API, Azure, jQuery,
Highcharts, and Angular. Sourabh has been awarded MVP status. He has
the zeal to learn new technologies and enjoys sharing his knowledge on
several online community forums.
He is a founder of IECE Digital and Sourabh Mishra Notes—online
knowledge-sharing platform where people can learn new technologies
easily and comfortably.
He can be reached through the following platforms:
Email: sourabh_mishra1@hotmail.com
YouTube:
https://www.youtube.com/@SourabhMishraNotes
Instagram:
https://www.instagram.com/sourabhmishranotes/?
hl=en
Twitter: @sourabh_mishra1
Part I
Basic Form Improvements
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2023
J. Harder, Enhancing Adobe Acrobat Forms with JavaScript
https://doi.org/10.1007/978-1-4842-9470-3_1
Chapter Goal: Creating the right form before you add JavaScript to
your PDF fields takes time and careful planning. Therefore, it’s
important that you become familiar with each of the form tools and the
properties that are associated with them. This chapter provides a quick
overview of forms, fields, properties, and tabs that will serve as the
basis for future chapters. If you are already comfortable with these
topics, feel free to jump ahead to Chapter 2.
Forms Review
Each form field has within it properties that can be accessed by right-
clicking the form field. The properties of that form field are organized
by tabs. Each form field has slightly different properties and therefore
different tabs.
Throughout this book you will be working on lessons with a variety
of different PDF forms and documents for a fictitious company called
the Tourmaline Mining Corporation.
Each chapter (except for Chapters 1 and 5) comes with JavaScript in
a .txt file and PDF files that you can open and compare. You can either
view the final PDF file or use the start PDF file and follow along with
the notes in these chapters. You can find the link to these files in the
introduction and then locate that specific Chapter Project folder.
Note Please be aware that the PDF files used with this book should
be opened only in Adobe Acrobat Pro, Acrobat Reader, or earlier
versions of Acrobat DC and not in your web browser or any other
PDF creation/reader program. Other PDF readers have been known
to corrupt the JavaScript code within the Acrobat PDF files, and then
the calculations fail to work.
Upon opening Acrobat Pro, make sure to check your preferences at Edit
➤Preferences ➤ Forms. Refer to Figure 1-1. They should be set to the
default settings shown in Figure 1-2.
Figure 1-1 Open Acrobat Pro using your Creative Cloud Desktop App
Figure 1-2 Default settings for the Forms tool found in the Preferences
In this case, all of the General check boxes are enabled.
Automatically calculate field values
Automatically adjust tab order when modifying fields
Show focus rectangle
Show text field overflow indicator
Show field preview when creating or editing form fields
Automatically detect Form Fields
Auto-enable text editing in Prepare Form
Highlight Color’s check is enabled to show border hover color for
fields. Light blue is the color for highlighted fields, and red is the
highlight color for required fields.
Auto-Complete is set to Off, and there is a description below it
explaining what this setting means. Other options in the list are Basic or
Advanced.
At this point, if these are your settings, you can click Cancel and Exit
or make your settings like mine and click OK. These preferences are not
saved with the forms but will help you interact with the forms as you
work.
If you are working with Manage Barcode Parameter, refer to this
topic later in the chapter and Chapter 19.
The book assumes you are familiar with filling in basic forms or
have used PDF forms in the past. If you are unsure of how to use the
Prepare Form tool and its autodetection of fields in Acrobat Pro, this
section provides a refresher.
Draw your form either by hand or create the basic structure in MS
Word, Adobe Illustrator, or Adobe InDesign, and then decide what steps
you want the form to do and accomplish. Then plan how to execute
your goals. Is what you want the form to do possible? Do you need to
simplify the form? Or do you need to learn more about the topic of
forms to create what you want? Make sure to consult with your team or
clients as you build the form before you begin to add interactivity.
Except for the program of Adobe InDesign, you cannot assemble the
form’s interactive fields outside of Acrobat, so you need to make a PDF
to do that. Until you are ready to make the PDF, continue to assemble
the form in your layout program such as MS Word until it looks the way
it should. Then save the MS Word file (.doc or .docx). Then create the
PDF. For example, in the case of MS Word, I can use my Acrobat tab to
quickly create a PDF or use my File Print tab. Refer to Figure 1-3.
Figure 1-3 Use the MS Word Ribbon with the Acrobat tab or the Print settings to
create your PDF
Once you have the final PDF, open it in Acrobat Pro and follow these
steps to add interactivity:
1. Click the Tools tab and click the Prepare Form tool, which is found
in the Forms & Signatures section (see Figure 1-4).
Figure 1-4 Location of Prepare Form tool
2. You can use this tool whether you have a PDF Form open or not.
While in the tool, choose, in this case, Single File, locate your file
(you can change the files if the thumbnail is not correct), and make
sure that form field autodetection is on. Do not select “This
document requires signatures” as we will look at that option in
Chapter 20 in more detail (Figure 1-5).
Figure 1-5 The Prepare Form tool when you first create a new form
3. Click Start. Acrobat will scan the file for fields; if it detects any, it
will create the field. However, it is not perfect in its detection, so
you may have to add, delete, or edit some fields afterward.
4. Once you have added your fields, save the file as a new PDF
(Ctrl/Cmd+S). Choose to save the file on your computer and then
select a folder to save the file into. Make sure that the “Convert to”
option is disabled. The new PDF is now an interactive form. Refer to
Figure 1-6.
Figure 1-6 Saving the new PDF form in a folder after autodetection is completed
Note You can now, with the Prepare Form tools, create a PDF form
in three more ways; refer to Figure 1-5: directly from your scanner,
as a blank new document using the Create New option, or using the
Create a Web form. We’ll look at that option in Chapter 20.
You can now begin adding your formatting and actions to the
properties of each field. Test it, and ask others to try it on their
computer, before you email it to your clients. Always keep a backup on a
disk or USB drive in case something happens to your main computer.
Also, make a printout of the PDF and all code in case you need to refer
to it later for another project. In this book I have placed a copy of the
code in the .txt files in each chapter for reference.
Once the fields are in the saved form, you can open the fields at any
time with the Prepare Form tool; you do not need to run the
autodetection again for that form. Refer to Figure 1-7.
You can exit the Prepare Form area partially by toggling the
Preview/Edit button in the upper-right (Figure 1-7). To exit the Prepare
Form tool completely, you must click the Close button in the upper-
right (Figure 1-7).
Figure 1-7 The Prepare Form tool and the tools for adding and working with the
fields. Note the Preview/Edit toggle and Exit (Close) buttons in the upper right. Also
note the view of a form while in Edit mode before switching to Preview
For more information on basic forms or basic form creation, check
out the following links before you proceed any further in this book:
https://helpx.adobe.com/acrobat/using/pdf-forms-
basics.html
https://helpx.adobe.com/acrobat/using/create-
form.html
https://helpx.adobe.com/acrobat/using/creating-
distributing-pdf-forms.html
https://helpx.adobe.com/acrobat/using/filling-
pdf-forms.html
https://helpx.adobe.com/acrobat/using/pdf-form-
field-properties.html
The Adobe HelpX area for forms has additional links as well, and we
will look at some of those options later. But you can use this area as a
resource when you need to work with basic forms.
While working in the Prepare Form Tool area, you will come across
other form tools in the right-side pane, such as the Align and Distribute
options, and in the More drop-down menu (Figure 1-7). I will go into
more detail about this area and the JavaScript area later in the book.
However, you can also refer to the previous web links for more specific
details. Refer to Figure 1-8.
Figure 1-8 Additional options in the right-hand pane of the Prepare Form tool
Fields Refresher
Fields can be blank and inactive, or they can contain a script that, upon
entering or clicking a trigger, sets the action in motion. For example,
they can execute a menu item or import form data. In Acrobat Pro, the
Prepare Form Menu tool area contains all the field options listed next
plus the Selection tool and the newer options Edit Text and Images and
Add Text.
Fields can be used in any form, while the Selection tool is just an
arrow that allows you to select, size, and move them around. From left
to right, let’s look at the tool options in this section more closely; refer
to Figure 1-9.
Selection tool: This arrow allows you select, size, and move fields. It
can also be used to edit text boxes when they are added; you double-
click with the arrow on them. Refer to the arrow in Figure 1-9.
Edit Text and Images: This is not a field option, but it allows you to
edit the text or images surrounding the field while remaining in the
Prepare Form tool and saves you time rather than having to close the
tool and use the Edit PDF tool instead. When text is selected, the right
pane’s Format area changes so that you can edit the selected text or
image that is surrounded by a bounding box. Images can be scaled
and rotated as well. Refer to Figure 1-10.
Figure 1-10 Text change settings in the Prepare Form tool and the selected text with
a bounding box
Add Text: This is not a field option, but it allows you to add a new
text box while remaining in the Prepare Form tool and saves you time
rather than having to close the tool and use the Edit PDF tool instead.
Select the tool and click a location on the page that you want the
text to appear and start typing, or when you select the tool, drag out a
rectangular bounding box for a paragraph area and start typing.
Again, the bounding box will appear around the text, and you can
scale and rotate as well as edit the format of the text on the right.
Refer to Figures 1-10 and 1-11.
Figure 1-11 Adding text to a page while in the Prepare Form tool and tip message
Click the Selection tool arrow if you want to exit the editing
options.
Now look at the form fields. These can be added to the form when
you first select them and then click the page. Use your mouse to
hover over each field to read its description and related name.
Text field: Type text, words, or numbers into the field. Refer to
Figure 1-12.
Figure 1-12 Adding a text field
Check box: Select one or multiple options of an item. Refer to Figure
1-13.
Radio button: Select one option from a group: yes or no. These
options can be mutually exclusive, and you can have more than one
group in a form. You must have at least two radio buttons and can
add a second if prompted with the initial message. Refer to Figure 1-
14.
Figure 1-14 Adding a radio button
List box: Select one or multiple items in a list of choices. Refer to
Figure 1-15.
Figure 1-15 Adding a list box
Dropdown list: Select an option or choice from a list. Refer to Figure
1-16.
Date field: This is the same as a text field but is preformatted to date.
It can operate as a date picker. Refer to Figure 1-19.
Another random document with
no related content on Scribd:
[6] Et disent que on tenoit à grant sens d’un signeur,
quant il a pluiseurs guerres en un temps, et il en poet
l’une atriewer, l’autre apaisier et le tierce guerroiier.
Tant li moustrèrent de raisons qu’il s’i acorda et pria
5 au prelat dessus dit qu’il y volsist aler. Li evesques
ne li volt mies escondire, ains se mist au chemin et
en ala celle part, mais il perdi sa voie et revint en arrière
sans riens faire. Si raporta au roy d’Engleterre
que li rois David d’Escoce n’avoit point de conseil
10 de donner triewes ne souffrance, ne de faire pais ne
acord, sans le gret et le consent dou roy Phelippe de
France. De ce raport eut li rois englès plus grant
despit que devant; si dist tout hault que ce seroit
amendet temprement, et qu’i[l] atourroit telement le
15 royaume d’Escoce que jamais ne seroit recouvret. Si
manda par tout son royaume que cescuns fust à
Evruich à le feste de Paskes, apparilliés d’aler là où
il les vorroit mener, excepté chiaus qui s’en devoient
aler en Bretagne avoecques monsigneur Robert d’Artois
20 et la contesse de Montfort.