Beginning JavaScript for Adobe Acrobat A non programmer s Guide John Deubert download
Beginning JavaScript for Adobe Acrobat A non programmer s Guide John Deubert download
https://ebookname.com/product/beginning-javascript-for-adobe-
acrobat-a-non-programmer-s-guide-john-deubert/
https://ebookname.com/product/adobe-acrobat-8-for-windows-and-
macintosh-visual-quickstart-guide-1st-edition-john-deubert/
https://ebookname.com/product/ivor-horton-s-beginning-
visual-c-2010-wrox-programmer-to-programmer-1st-edition-ivor-
horton/
https://ebookname.com/product/learning-javascript-design-
patterns-a-javascript-and-react-developer-s-guide-2nd-edition-
adnan-osmani/
https://ebookname.com/product/fundamentals-of-healthcare-
finance-1st-edition-louis-c-gapenski/
Essentials of Business Communication Book Only Eighth
Edition Mary Ellen Guffey
https://ebookname.com/product/essentials-of-business-
communication-book-only-eighth-edition-mary-ellen-guffey/
https://ebookname.com/product/funny-pictures-animation-and-
comedy-in-studio-era-hollywood-1st-edition-daniel-goldmark/
https://ebookname.com/product/indigenous-peoples-and-ethnic-
minorities-of-pakistan-constitutional-and-legal-perspectives-1st-
edition-shaheen-sardar-ali/
https://ebookname.com/product/the-dixon-rule-1st-edition-elle-
kennedy/
https://ebookname.com/product/instrumentation-theory-and-
applications-1st-edition-satya-sheel/
Innovative drug development for headache disorders 1st
Edition Jes Olesen
https://ebookname.com/product/innovative-drug-development-for-
headache-disorders-1st-edition-jes-olesen/
switch (itemPicked) {
{
Statement.nextRow() case "See close-up":
ar row = gStatement.getRow() this.pageNum = 2
opulateFields(row) var gHelpText = [
Beginning
ostMessage("") “What’s your full name?”,
“Where do you live?”,
break
case "About the artis
Adobe Acrobat®
app.beep()
app.alert("Your order has been submitted.")
A non-programmer’
}
s guide
else {
if (pwd != null)
app.alert("That is not the password!\n\n
¬ (Hint: it’s a small, rather repulsive amphibian.)")
}
E
var re10Digits = /^(\d{3})(\d{3})(\d{4})$/
John Deubert
if (re7Digits.test(event.value))
QDGuides
var orderInfoTemplate = this.getTempla
var addressTemplate = this.getTemplate
Quality Electronic Documentation
event.value = RegExp.$1 + "-" + RegExp.$2 from Acumen Training
ISBN-13: 978-0-9850512-0-4
ISBN-10: 0-985-05120-5
Version 1.1
Notice of Rights
All rights reserved. This book may not be redistributed to another computer.
Notice of Liability
The information in this book is distributed “as is,” without warranty. While every precaution has been taken
in the preparation of the book, the author shall not have any liability to any person or entity with respect to
any loss or damage caused or alleged to be caused directly or indireclty by the instructions contained in this
book or by the computer software and hardwre products described in it.
Trademarks
Trademarks are used throughout this book. Rather than put a trademark symbol in every occurrence of a
trademarked name, we aver that we are using the names in an editorial fashion only and to the benefit of the
trademark owner with no intention of infringement of the trademark.
–i–
QED Beginning JavaScript for Adobe Acrobat
Table of Contents
2 Page and Document JavaScripts 16 12 Formatting Text Fields with Regular Expressions 94
In which we learn the basics of creating and editing JavaScripts in Acrobat. In which we use regular expressions to automatically re-format user’s text input.
–ii–
QED Chapter 0
Introduction
You are about to open a new chapter in your work with Acrobat forms. In reading this book, you will learn
how to add features and abilities to your forms that are not otherwise possible: roll-over help, automatic text
field formatting, database connectivity, and more will all become routine parts of your form design. You will
also learn a programming language, perhaps your first: JavaScript. Even if you’ve never had a hankering to
write software and sling code, you’ll find JavaScript an important arrow in your quiver; it’s supremely useful,
relatively easy, and surprisingly fun.
Of course, you don’t need JavaScript skill to create an Acrobat form; you’ve no doubt been doing perfectly
well for quite some time without it. However, a knowledge of JavaScript adds immeasurably to your ability
to make your forms look and behave exactly as you want. JavaScript will open to you a world of possibility
whose scope is hard to overstate. Sufficient to say that the knowledge and techniques you will learn in this
book will allow your forms to take on a sophistication that is otherwise completely impossible.
This Book
If you are an experienced Acrobat form designer, but have never written a line of programming code in your
life (and pretty much wanted to keep it that way), then this book is written for you. Together we’ll explore
programming concepts while learning how to add features to your Acrobat forms: we discuss arrays while
creating a dynamic list of prices; we talk about case statements while creating a pop-up menu; we teach a
form to check the version of Acrobat on which it’s running and, along the way, talk about if–else constructs.
When you’re done with the book, you will be in good shape to read more formal books on JavaScript and to
make use of Adobe’s technical specification of Acrobat JavaScript.
–iii–
QED About the Book
What this book isn’t
This book is not a complete reference to the JavaScript language or to using JavaScript in Acrobat. JavaScript
is a broad and deep language and is capable of much that we don’t discuss here.
The purpose of this book is to bootstrap you to a point where you can learn the rest of the language’s
abilities on your own; it assumes you are an experienced Acrobat forms designer, but have little or no
experience with computer programming languages. If you are already comfortable with Objective C, Java, or
other programming language, this book will be paced too slowly for you; you should go directly to Adobe’s
Acrobat JavaScript Object Specification.
Also, this book does not teach you how to make form fields and other components of Acrobat forms;
I assume you have reasonable experience with the mechanics of designing and creating forms.
Mac or Windows?
With one exception the examples in this book will work with either the Macintosh or Windows version of
Adobe Acrobat. The exception is the pair of chapters on Acrobat database connectivity, which is available
only in Windows. Otherwise, the Mac and Windows versions of Acrobat work identically, except for minor
differences dialog box labelling, etc. Illustrations in this book are taken from both versions of Acrobat.
Some chapters need to be read in order; for example, the discussion of regular expressions is spread across
Chapters 10, 11, and 12 and they must be read in that order to be sensible at all. Most chapters, however, are
intended to be semi-independent.
All of the chapters, however, assume you have read Chapters 1 and 2.
–iv–
QED About the Book
Reading the book on-screen
Being an e-book, Beginning JavaScript for Adobe Acrobat is distributed electronically; its pages are designed
to be easily read on-screen. Since it’s distributed as a self-contained pdf file, you can read the book on nearly
any computer or tablet. It turns out that the page size works particularly well on a 768x1024 screen, such as
that of the iPad; that’s probably a coincidence.
The pdf file has been “enabled” for commenting in Adobe Reader, so you should be able to make notes to
yourself on the pages in either the full Acrobat or Reader.
URL links within the book are all “live” and will open the appropriate page in your default web browser.
If you register your book purchase (go to www.acumentraining.com/QEDGuides/qedregister.html), you’ll Figure 0.1 This book’s page size works well printed two-up on A4 or
American Letter-size paper.
be notified whenever there is a new update for your book. It’s worth doing.
–v–
QED About the Book
Online Resources
There are two sources of information that are specifically intended to be used with this book.
■ The complete, functioning form, with all JavaScripts in place. This shows you how the form is supposed to
behave and allows you to inspect the chapter’s JavaScripts in place. This version of the form has a filename
ending with “end.”
■ A version of the form with all form fields and other elements in place, but no JavaScripts attached. Use
this version if you want to follow along while reading the chapter, writing, debugging, and executing the
JavaScripts as you go. The file for this version of the form will have a name ending in “start.”
The sample form files are available for downloading at www.acumentraining.com/QEDGuides/acrojs.html. This
web page is also where you will find errata, update information, and other useful information.
Figure 0.2 Each issue of the Acumen Journal has an Acrobat-related article; many of
these are about JavaScript usage.
Acumen Journal
The Acumen Journal (Figure 0.2) is a free periodical that I produce three or four times per year. Each issue has
an article on advanced Acrobat usage and many of these are about JavaScript. The back issues make a good
supplemental to the topics in this book; there are more than 60 issues accumulated since I began writing the
Journal back in 2000. You can download them at www.acumentraining.com/acumenjournal.html.
If you wish to be notified when a new issue of the Journal comes out, there is a link on the Acumen Journal
web page to an appropriate form.
Thank You
Finally, thank you for buying this book or looking at the sample chapters. Either way, you are participating in
an ongoing experiment in publishing.
–vi–
QED Chapter 1
Welcome to JavaScript
Periodically in life, you learn something that broadens your world immeasurably, revealing an expanse of
What We’ll Learn in this Chapter
new experience, problems, opportunities, play, and work. Whole worlds that had invisibly surrounded
In this chapter, we’ll learn:
you suddenly appear, providing a new space to explore. Reading, sex, driving, children, all bring with them
concerns, interests, and interactions that had been previously inaccessible and unsuspected. ■ What’s a JavaScript?
In its own small way, learning JavaScript will be just such a threshold event in your professional life. If you’ve ■ Types of JavaScript
been working with Acrobat for any length of time, you’ve probably gotten pretty good at it and have ■ Attaching a JavaScript to a form field
become quite comfortable at creating forms, adding music, creating slide shows, and all the other features
■ JavaScript objects, data types, and syntax
Acrobat offers.
■ JavaScript errors and the debugger
This book introduces the New World. A knowledge of JavaScript allows you to do things within Acrobat that
■ How to use your own text editor with Acrobat
far exceed what you’ve done so far: You can interface with databases; add your own pop-up menus; create
JavaScripts
forms with sophisticated, interactive interfaces; and implement form fields that can look up p rices and other
data. These are only a few of the things you can do within your Acrobat documents using JavaScript. The
extent to which you can manipulate your Acrobat files is vastly greater with JavaScript skills than without.
Here you will learn how to accomplish a variety of useful tasks in Acrobat using JavaScript. Along the way, you
will learn a great deal about JavaScript, programming, and Adobe Acrobat.
Beyond that, this book does not assume any knowledge of programming; you will learn the programming
skills you need as we proceed through our examples.
Again, this book is intended for programming novices; if you are an experienced programmer, you may it to
be paced slower than you’d like. Experienced programmers may do better to just go to a more-advanced
book to learn JavaScript (there are myriad such books, though they all teach JavaScript in the context of web
pages) and then look at Adobe’s JavaScript reference site to see how to apply it to Acrobat.
–1–
QED 1. Welcome to JavaScript
What Version of Acrobat Should You Have? Books on Acrobat Forms
Although this e-book presumes you are working with Acrobat XI, the current version, it works equally well Although there are a number of books that will teach you how
with Acrobat X, whose interface is nearly identical. The instructions we step through will nearly all apply to to create Acrobat forms., most of them are out of print. The only
Acrobat 9, as well. Where there is a large difference in Acrobat 9, I’ll provide a note on what you should do extant book is:
in the earlier software. • PDF Forms Using Acrobat and LiveCycle Designer Bible
Ted Padova and Angie Okamoto
What Is JavaScript? Ted Padova is the king of the “Bible” style books and this
volume shows why.
JavaScript is a programming language. The term “programming language” often induces jitters in n ewcomers,
but, conceptually, it’s not very scary: A programming language is a language that is used to describe the There are other books specific to Acrobat forms that, though
steps involved in carrying out some task. In Acrobat, these tasks include moving to a particular page of a out of print, are still available if you look around. In particular, my
own old book is still available, though it’s getting pretty long in
document, sending data to a database, and calculating a form field value. Carrying out the steps described
the tooth, I admit:
by a JavaScript is referred to as executing the program.
• Creating Forms in Adobe Acrobat – John Deubert
As a programming language, JavaScript’s most significant characteristic is that it’s simple enough that many
Finally, any reasonably complete book on Adobe Acrobat will
applications use it as their built-in scripting language. Web browsers can all interpret JavaScripts embedded
have at least a chapter or two on creating forms. This includes my
in Web pages, and, particular to our topic, Acrobat can execute JavaScripts attached to form fields, pages,
own book:
and pdf files.
• Adobe Acrobat X: Visual Quickstart Guide – John Deubert
Like any language, JavaScript has its own vocabulary (words that have meaning) and syntax (rules by which
• Acrobat X Classroom in a Book – Adobe Creative Team
you make statements with those words). Learning JavaScript, therefore, has much in common with learning a
human language, such as Spanish or German, only it’s much easier. JavaScript is vastly simpler than any human • Acrobat X PDF Bible – Ted Padova
language: there are no metaphors, no literally nonsensical idioms, no synonyms, no subtle shades of meaning. These are all available through Amazon.com, as is pretty much
Just very precise statements telling Acrobat to do something very specific. everything in the world.
JavaScript in Acrobat
Acrobat allows you to create five different kinds of JavaScripts:
■ Form Field JavaScripts are attached to form fields. Acrobat executes the script when a particular event
occurs in that form field, such as a button click. Most JavaScripts in Acrobat are attached to form fields.
■ Page JavaScripts are executed when the user moves to or leaves a particular page in the Acrobat document.
■ Document Action JavaScripts are executed user opens, closes, saves, or prints a document.
–2–
QED 1. Welcome to JavaScript
We shall talk about Page, Document, and Document Action JavaScripts in Chapter 2; we won’t be discussing
application JavaScripts at all in this book. For now, let’s look at how you type in and use a Form Field JavaScript.
This form consists of a set of flash cards that are intended to be printed double-sided and then used to quiz
students on vocabulary terms. Our pdf file has only a few flash cards; each card has a button that takes u sers
to an order form they can use to purchase the complete set of cards. We are going to add a JavaScript to
the Order Form button that takes the user to the order form, located on the last page of the Acrobat file
(Figure 1.2).
As will be true throughout this book, there are two versions of this form on the JavaScript for Acrobat web page:
–3–
QED 1. Welcome to JavaScript
Attaching a JavaScript to a Form Field
As a reminder of something you may already know, let’s step through the process of attaching a JavaScript to
a button, in this case our Order Form button.
Figure 1.3 Enter Form Editor mode by
To attach a JavaScript to a button: clicking the Edit button in the Forms
x Note
panel.
Start with the form open in Adobe Acrobat and the Tools
pane exposed. Acrobat 9 doesn’t have a Tools pane, but
it does have a Forms menu. To get to the Form
1 In the Tools pane’s Forms panel, click on the Edit tool Editor, select Forms > Add or Edit Fields. Having
(Figure 1.3). done this, you can follow the steps exactly as listed.
Acrobat will present you with the Field Properties dialog box (Figure 1.5). Figure 1.4 Acrobat’s Form Editor mode gives you a Forms pane, new
toolbars, and presents each form field as a rectangle with handles..
3 Click on the Actions tab.
You will now be looking at the set of controls that specify what
should happen when you click on this button (Figure 1.6).
This tells Acrobat that this button’s action should trigger when
the mouse button is released after clicking in the b utton. (See
the sidebar, at right.)
–4–
QED 1. Welcome to JavaScript
6 Type your JavaScript into the text field of this dialog box. Form Field Events
In the case of our order form, the JavaScript is a two-line The Select Trigger pop-up menu, shown in Figure
program that moves the user’s view of the document to 1.6, offers six form field events to which you can
the page containing the order form and then causes the attach an action:
user’s computer to beep: ■ Mouse Down occurs when the user presses the
mouse button with the pointer in the form field.
this.pageNum = 6
app.beep() ■ Mouse Up occurs when the user clicks on the
field and then releases the mouse button with
Type these lines into the text-editing field exactly as the mouse pointer still in the field.
above, making sure to match upper and lowercase. The Figure 1.7 The JavaScript Editor window is a simple text editor that you
first line of code says, “In this document, set the current ■ Mouse Enter occurs when the mouse pointer
will use to type in your JavaScripts.
first rolls over the form field.
page number to 6.” The second line tells the Acrobat
application to beep. ■ Mouse Exit occurs when the mouse pointer rolls
out of the form field.
7 Click the ok button of the JavaScript Editor and the Close
■ On Focus occurs when the user clicks on or tabs
button of the Field Properties dialog box to return to the
into the form field, so that it becomes the target
Acrobat form.
for keyboard or other input.
You are now looking at the Acrobat flash card page with ■ On Blur occurs when the user tabs out of a form
the Form tool still selected, as in Figure 1.4. field or clicks on some other form field, so that
our field is no longer the target for user input.
8 Exit the Form Editor by clicking the Close Form Editing (Blur is the opposite of Focus, of course.)
button in the Forms pane (Figure 1.8).
The Field Properties dialog box, Figure 1.6, lets you
You are now back where you started, looking at your associate one or more A ctions (a JavaScript action,
Figure 1.8 You exit the Form Editor by clicking Close Form Editing button.
document page. in our case) with any of these events.
This button is in the Forms pane in Acrobat X (above right) and above the
pane in the newer Acrobat XI (above left).
So, now try it out. Click the Order Form button, and Acrobat
will move to the order form page and then beep.
JavaScript Objects
Our two-line JavaScript makes use of two JavaScript objects. A JavaScript object is the representation of some
piece of data within your JavaScript program. Before your program can manipulate or examine a form field, it
must first create an object that represents that field. Most of the things you can manipulate in JavaScript (pages,
signatures, database connections, and so on) are represented in your program as objects.
In our sample program, this refers to a Doc object. A Doc object represents an open Acrobat file to your
JavaScript program; you use this object to change pages, save the document, and otherwise manipulate the
–5–
QED 1. Welcome to JavaScript
document from within your program. The word this in our sample JavaScript refers particularly to the A crobat
document in which our JavaScript resides (the Flash Cards file, in our case); think of it as short for this document.
The word app is an App object, a reference to the Acrobat application being used to view the current
document. You use an App object to tell the Acrobat application to do something: open a file, put up an
alert dialog box, or, in our case, beep.
■ Annot represents an annotation (for example, a “sticky note”) in the current document.
■ App represents the Acrobat application being used to view the current document.
–6–
QED 1. Welcome to JavaScript
The phrase this.pageNum addresses the pageNum property of the Document object; this property is the “Program” vs. “Script” vs. “Code”
page number the document is currently displaying to the user. Our program moves the user to the order
Here are three closely related terms that we’ll be using
form page by setting the current document’s pageNum property to the order form’s page number:
throughout this book.
this.pageNum = 6
■ A program is a general term for a series of instructions that
Some observations about this page number assignment: tell a computer in detail how to carry out a particular task. In
general, a program is a stand-alone set of instructions, such as
■ You address the property of an object by naming both the object and the property, joined by a period: an application.
Object methods
A method is a command that is associated with a JavaScript object. Just as a dog can be given commands
(“Sit,” “Heel,” “Spit that out this instant!”), JavaScript objects have commands that they can carry out. The set of
commands is different for each type of object. For example, Table 1.2 lists some of the commands the app
object knows how to execute.
–7–
QED 1. Welcome to JavaScript
In our Order Form JavaScript, we executed (“called”) the app object’s beep method:
app.beep()
Note that we call an object’s method in the same way that we refer to one of its properties: the object
name, a “dot,” and the method name. The method name is followed by parentheses enclosing the method’s
arguments; let’s talk about what those are.
The above JavaScript statement would open an Acrobat file named TermPaper.pdf. Note that our earlier call
to app.beep had empty parentheses because the method doesn’t take any arguments; you still need the
parentheses, though.
Sometimes when you give a dog a command, you expect the dog to give you something back: the command,
“Fetch the stick, boy!” should yield a stick in your hand (along with some gratuitous drool). S imilarly, many
JavaScript methods have a return value, some piece of data they give back to the JavaScript program.
The openDoc method we invoked above actually returns a Doc object representing the newly opened
document, though our single-line use of openDoc just ignores it. We shall look at return values in much more
detail in the next chapter.
Named Arguments
Generally, you must supply arguments to a method in a certain order; the app object’s alert method, which
we’ll talk about in detail in the next chapter, wants a string and an icon code:
app.alert("Woah! Somethin' weird just happened!",2)
The string and the integer must be supplied in that order so that JavaScript can identify them.
However, you can also pass arguments to a method by name. The Acrobat JavaScript Guide (described at the
end of this chapter) defines a name associated with each of the arguments a method requires; in the case of
app.alert, the names are cMsg and nIcon.
–8–
QED 1. Welcome to JavaScript
You can supply these arguments, in any order, using the following call to the method:
app.alert({cIcon: 2, cMsg:"Woah! Somethin' weird just happened" })
Note that we have braces within the method’s parentheses and within those we have our method arguments.
Each argument is represented by the name of the argument, a colon, and then the argument’s value; the
arguments are separated by commas.
This is not as concise as passing the arguments by position, but it is clearer as to the purpose of each of the
arguments. (Our first call to app.alert, for example, gives no clue to the purpose of the 2.) Also, passing
arguments by name give you great flexibility in formatting your code. In particular, you can place line breaks
within the argument list and supply the arguments in any order; our previous example could have been written
app.alert({ cIcon: 2,
cMsg: "Woah! Somethin' weird just happened" })
In this book, we shall pass arguments by position; we’ll use argument names only when it’s necessary—usually
for clarity—to a particular JavaScript example. I shall, however, often supply the names of the arguments when
describing methods so that you can use them if you wish.
JavaScript Statements
A JavaScript program—any computer program—consists of a series of statements, each of which carries out
one step in the overall task. Our sample program consists of two statements: a page assignment and a call to
the app object’s beep method.
this.pageNum = 6
app.beep
Usually, each line within a JavaScript program will contain a single JavaScript statement, as in our program. You
can put more than one statement on a line, separated by semicolons. Our two-line program could have been
written on a single line:
this.pageNum = 6; app.beep
–9–
QED 1. Welcome to JavaScript
Why would you do this? Purely for esthetics; some people just prefer to combine very simple statements
together. I recommend against this practice; most programs are much easier to read if you have only one
statement per line.
If you read other people’s JavaScripts, you may notice that many programmers put semicolons at the end of
every line in their program:
this.pageNum = 6;
app.beep;
This doesn’t hurt anything, but it’s unnecessary. Most of them do it out of habit; JavaScript looks very much
like the programming languages C and C++, both of which require that all statements end with s emicolons.
You can leave out the semicolons.
JavaScript Text
JavaScript programs are simply text files; you can write them with any text editor or word processor and then
copy and paste them into the Acrobat JavaScript Editor dialog box. In fact, Acrobat lets you specify an e xternal
editor that should be used for editing your JavaScripts; we’ll discuss how to do this at the end of the chapter.
By the way, space and tab characters within a JavaScript line have no particular meaning in JavaScript. You can
use them as you wish to format your program. This is a purely visual issue; you want to format your JavaScript
code so that it’s easy to read.
Use whitespace characters lavishly! Reading program code is tedious at best; a program can be nearly
undecipherable if the programmer has not formatted the code for easy reading. This is an important enough
issue that I shall be providing formatting tips for many of the JavaScript constructs we use in this book.
JavaScript Comments
JavaScript code can be pretty cryptic. Puzzling over someone else’s code (or even your own code from six
months ago), trying to figure out exactly what it’s trying to do, can be tedious. As a courtesy to others looking
at your code and as an aid to your future self, it is very important to place comments in your JavaScript code.
A JavaScript comment is text in your code that is ignored by the JavaScript “machine.” The purpose is to let
you place your own notes to be read by human beings examining the code.
–10–
QED 1. Welcome to JavaScript
JavaScript recognizes (that is, ignores) two kinds of comments:
■ Single-line comments start with a double slash (//) and extend to the end of the current line in the
JavaScript code. These are intended for brief comments.
// This is a single-line comment.
■ Block comments start with a /* and end with a */. Between these two delimiters can be as much text as
you wish, spread out over as many lines as you wish within the JavaScript file. Use this for longer comments.
/* Here we have a block comment.
This text will be completely ignored
until we end the comment, right here. */
An Example
Consider the following, uncommented JavaScript from later in this book:
var txtField = event.target
txtField.fillColor = color.red
txtField.textColor = color.white
Since we have not yet discussed these commands, the exact purpose of this script and how it carries out that
purpose is very unclear, although it does seem to have something to do with color.
On the other hand, if we include comments in the code, then it becomes possible for someone unfamiliar
with the program to at least know what the intent of the program is and generally what it’s doing:
/* This program changes the background and text color of
a text field when the user tabs into or clicks in the
field. */
var txtField = event.target // Get a reference to the text field
txtField.fillColor = color.red // Set the background to red
txtField.textColor = color.white // Set the text color to white
This version of the program is much clearer, even to someone new to the code.
Comments are a Force for Good in programming. Any script more complex than a couple of lines should
include comments that describe what it does and how it works.
All of the examples in the rest of this book will be heavily commented to make them as comprehensible as possible.
You’re welcome.
–11–
QED 1. Welcome to JavaScript
JavaScript Errors
In the (ahem) rare event that you have an error in your JavaScript—you misspelled a variable name, mis-copied
a piece of code, and so on—you will be faced with the task of figuring out what is wrong with your code,
a process known as debugging. Acrobat left to itself treats these errors quietly; if the code fails, Acrobat
just aborts the script; to all appearances, clicking on the button did nothing at all, although there was really
a failed script h appening beneath the hood. This isn’t useful for debugging; if a JavaScript fails, we’d like to
know about it and, furthermore, be told what went wrong, so we can fix it.
To get this diagnostic information about failed scripts, we need to enable something called the JavaScript Debugger.
With the JavaScript Debugger enabled, whenever one of your JavaScripts fails, Acrobat will open the
Debugger with an error message (“ReferenceError,” in Figure 1.9). This will allow you to determine what went
wrong and what to do about it.
Error messages can be somewhat cryptic at first, but with time and familiarity they become useful. The most
common messages you are likely to see are the following:
This indicates that you misspelled something; the name “xxx” (or whatever) is not one that JavaScript Figure 1.9 The JavaScript Debugger window presents information about errors in
knows. Remember that JavaScript is case-sensitive; there is a difference between app (which JavaScript your JavaScript, as well as providing a variety of other tools.
knows) and App (which it doesn’t know).
■ Syntax Error
This means that JavaScript could not make sense of something in the code. This usually means you omitted
something (a comma, a number, a parenthesis) from your script. An example of a syntax error would be
app.alert("Hi, Mom", 3
The set of possible error messages is very large, though most are pretty hard to provoke. Just sit tight, read
the message, and carefully examine the aberrant JavaScript code for misspellings and omissions.
–12–
QED 1. Welcome to JavaScript
Enabling the JavaScript Debugger
You enable the JavaScript debugger in the Preferences of your copy of Acrobat. Open your Acrobat
preferences and select JavaScript in the long list of preference categories (Figure 1.10). All of the checkboxes
in the JavaScript Debugger section should be selected, as in the figure.
You can ask Acrobat to use text editing software of your choice to edit your JavaScripts. Having told A
crobat
Figure 1.10 You enable the JavaScript debugger in your Acrobat preferences. Select
what editor you want to use, it will automatically launch this software when you click on the Add or Edit
all of the checkboxes in the Debugger section, as above.
button in the Document JavaScripts dialog box (Figure 1.11).
To set this up, you must specify in Acrobat’s Preferences the editor you wish to use for working with JavaScripts.
Acrobat will present you with its Preferences dialog box (Figure 1.12, next page).
The Preferences dialog box will display the controls that affect Acrobat’s JavaScript support, as in Figure 1.12.
3 Among the JavaScript Editor controls, at the bottom of the dialog box, select Use External JavaScript Editor.
Figure 1.11 Acrobat will launch your external text editor whenever you click the Ad
4 Click the Choose (Windows) or Browse (Mac) button and then navigate to the .exe or .app file for the
or Edit button in the Document JavaScripts dialog box.
editor you want to use when editing JavaScripts.
That’s all there is to it. Now, when you edit a JavaScript, Acrobat will automatically launch your text e ditor.
Type your JavaScript code into the text editor’s window, save the text, and then close the editor. Your
JavaScript will be automatically entered into Acrobat.
–13–
QED 1. Welcome to JavaScript
For what it’s worth, my favorite programmers’ editor on the Mac is TextWrangler (www.barebones.com); it
is a first-rate editor and completely free, omigawd. Among Windows text editors, I’m rather fond of TextPad
(www.textpad.com); it’s relatively inexpensive shareware and well worth the money.
JavaScript References
This book is a non-programmer’s introduction to using JavaScript within Adobe Acrobat; it offers full
coverage of neither the JavaScript language nor a complete description of the ins and outs of the Figure 1.12 You can tell Acrobat to use an external editor when typing or modifying
implementation of JavaScript that resides in Adobe Acrobat. When you are done with this book, you will JavaScript code.
have two other references you can use to further your studies.
Figure 1.13 shows a part of a page from the Reference. As you can see, this is not intended to be fun reading;
it’s a reference, not a tutorial. Still, if you want to learn the complete set of features that are built into the
JavaScript language (as opposed to the Acrobat version of it), this is the place to go.
–14–
QED 1. Welcome to JavaScript
Like the Client-Side Reference, the JSAPI is a technical specification, not a document you would willingly read
from one end to the other. It gives a detailed description of every JavaScript object type available in Acrobat
x
and the properties and methods of each. Where the book you are
Note
reading presents a series of examples of how to carry out specific
The JSAPI is available as a Kindle book from
tasks in JavaScript, the JSAPI describes everything you can do in amazon.com.
Acrobat with JavaScript.
To give you a bit of the flavor of the JSAPI, Figure 1.15 shows a screenshot of the complete description of the
app object’s beep method. I shall be making occasional r eferences to the JSAPI throughout this book.
Figure 1.15 The description of the app object’s beep method is a good
example of the type of description provided for every object., method, and
property in the JavaScript for Acrobat API Reference.
–15–
QED Chapter 2
Page and Document JavaScripts
There are five broad types of JavaScripts in Acrobat, each differing in where it’s used in the Acrobat document.
What We’ll Learn in this Chapter
■ Form Field JavaScripts are attached to form fields. As we saw in the previous chapter, Form Field scripts are In this chapter, we’ll learn how to:
associated with events that occur with a form field: Mouse Down, On Focus, and so on. ■ Run a JavaScript when a document opens
■ Document JavaScripts are associated with the opening of the Acrobat file. Acrobat executes these when ■ Run a JavaScript when a document closes
the document is first opened. ■ Run a JavaScript when entering or leaving a page
■ Document Action JavaScripts are executed when one of a set of predefined events happens with the ■ Using JavaScript variables
Acrobat file: the file closes, is saved, and so on.
■ Page JavaScripts are associated with a particular page. You can provide scripts that Acrobat will execute
when the user enters that page, leaves that page, or both.
■ Application JavaScripts are scripts that are executed by Acrobat when the application first opens. These
can perform a variety of interesting tasks, such as add items to the Acrobats menus. We won’t be talking
about application scripts in this book, because their use is specialized and infrequent; they’ll be a topic for
an eventual book 2.
We discussed Form Field JavaScripts in Chapter 1. In this chapter, we’ll look at how to write the other three
types of scripts.
The Project
(Files: JSAcro_Ch02_Example_Start.pdf, JSAcro_Ch02_Example_Final.pdf )
Our sample file for this chapter is the pet store catalog pictured in Figure 2.1. In the course of our discussion,
we’ll add examples of Document, Document Action, and Page JavaScripts to this file.
–16–
QED 2. Page and Document JavaScripts
The JavaScript Tools Panel
Several of the JavaScript-related tools we’ll be using in this chapter reside in the JavaScript panel in the
Acrobat X Tools pane (Figure 2.2).
If you examine your own copy of Acrobat, you’ll probably find the JavaScript panel is missing; A crobat Figure 2.2 The Javascript
doesn’t show this panel by default. (This is reasonable; the vast majority of Acrobat users don’t have anything panel lives in the Tools
pane. It is initially hidden.
to do with JavaScript and would be appalled at the prospect.) Before we can proceed further in this book,
we need to make the panel visible, thusly: The tiny icon in the upper-
right corner, just above
To make the JavaScript panel visible: the panels displays a
x Note
drop-down menu when
1 Make the Tools pane visible by clicking its name in the
clicked (Figure 2.3).
Acrobat X toolbar. Acrobat 9 doesn’t have a Tools pane. All of
the JavaScript commands in this chapter reside in
2 Click the tiny icon at the top of the Tools pane and select the Advanced>Document Processing submenu.
JavaScript in the resulting pop-up menu (Figure 2.3).
The JavaScript panel will become visible in the Tools pane. It will be available to your copy of Acrobat X until
you deselect it again.
Document JavaScripts
Document JavaScripts are executed by Acrobat upon opening the document to which they're attached. This is
a convenient way to present the reader with an initial “splash screen” or to carry out some other start-up activity
when the user opens your pdf file. You may attach as many Document JavaScripts to an Acrobat file as you wish.
As an example, we’ll add a Document JavaScript to our catalog that displays a greeting when the reader
opens the document (Figure 2.4).
Figure 2.3 Make the JavaScript panel visible by selecting it from the
To attach a Document JavaScript to an Acrobat document: Tools pane’s pop-up menu.
1 In the JavaScript panel, click the Document JavaScripts tool (back in Figure 2.2). Figure 2.4 We’ll start
by adding a Document
Acrobat will display the Document JavaScript dialog box (Figure 2.5 , next page). JavaScript that displays an
admittedly unattractive
2 Type a name for your script into the Script Name field. “welcome” message when
the pdf document opens.
–17–
QED 2. Page and Document JavaScripts
This can be any name you wish, although descriptive is
better than cryptic; we’ll name our script “Welcome,”
since that’s what it does.
This JavaScript displays the alert shown back in Figure 2.4. The app object’s alert method displays an
alert window with the specified text. The 3 indicates the kind of icon that should appear in the alert. We’ll
look at this method in more detail in Chapter 4. (You may recall we discussed the app object in C hapter 1.) Figure 2.7 Type your JavaScript into the text field of the JavaScript Editor.
Remember that JavaScript is case sensitive; your upper- and lower-case letters should match the line above.
5 Click ok to back out of the JavaScript Editor and return to the Document JavaScripts dialog box.
The dialog box will now show our Window script in its list of scripts (Figure 2.8). If you click on the
script in the list, the dialog box displays the code in the lower text field, as in the figure.
6 Click the Close button to exit the Document Scripts dialog box; you will now be back at your Acrobat
page. That’s it! We’ve created our Document JavaScript. Figure 2.8 Our
Welcome script is now
7 Try it out by saving the Acrobat file, closing it, and then reopening it. Acrobat should display the alert we listed in the D
ocument
saw in Figure 2.4. JavaScripts dialog
box. Click on the script
name and its text will
appear in the lower
text field.
–18–
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Ripeness is All
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Language: English
[Transcriber's Note: This etext was produced from Fantastic Stories of Imagination May
1962. Extensive research did not uncover any evidence that the U.S. copyright on this
publication was renewed.]
He was disturbed, but he did not know it. Murky, agitated waters
crept up in his vast subconscious world, and sought the threshold,
the mouth of the pit, the slope of the clean shore; little rainbows of
light now and then flashed over the waters. They heaved, and
against the sluice-gates they beat, sullenly. There was a yielding, but
the great force was contained.
He left his Pad, curiously mopping his brow a little, and furrowing it
between the eyes. It came to him that he was hungry. He stepped to
the curb, pushed the button, and leaned against the post, as if
waiting, or in thought. Almost immediately a Car appeared, in a
cheery orange and green. He almost shuddered, and he almost
knew that he did so. Then he brightened, stepped into the car, and
voiced his desire.
He was carried at a moderate pace through clean, broad streets and
past bright, shiny buildings and smiling parks and gardens. He came
to the top of a high hill, saw the sparkling blue bay in the distance,
and thought vaguely of sailing upon it. On his face he felt a brisk
spray, and the air was tanged with salt. Then a warmed, faintly
perfumed glow dried and composed him, and the Car shut off all its
machinery and glided to a stop. He got out, ever so comfortable,
and entered a luxurious Kitchen, in which he had not dined for
several days.
The doors opened automatically, and a smiling android, gaily
featured and clothed, conducted him to a table. She was a soothing
sight: yes, that's what it was. He ordered a sumptuous meal,
rubbing his ample waistline in anticipation.
"Dig dig!" crooned the waitress.
He patted good-naturedly her well-moulded behind as she turned;
she glowed sweetly back over her soft and delicate shoulder. He
wondered if Meg was enough, and decided that, well, for the time
being, he guessed she was. No use hurrying things. The waitress
returned and served the meal. As always, it was excellent. He
finished with a leisurely bottle of wine and a cigar, pinched the
waitress's firm yet ever so yielding thigh, and departed.
Then a deep stirring almost took hold upon him. Yes, that was what
he needed. It had been several months now. He pushed another
button, and a rosy pink Car appeared to his service. "Take me to a
House, you know what I mean?" he said, as he arranged himself
upon the pearl grey cushions. The Car glided away.
They went back to the mansion through the twilight, and established
themselves in one of the rooms. The soft curtains were drawn, the
Bed was large, the sheets were silky and creamy. She reclined on
her back, and the mattress moulded itself perfectly to her form.
He lay down beside her, and caressed her. She clasped him tight to
her breast. And he was clasped also by an invisible but very palpable
field of energy, that directed his movements and charged him with
an inexhaustible and ceaseless power. He held her tight, and the
force entwined them. They were one throbbing ecstasy, and only at
the very last endurable moment were they given release.
Then the Bed slowly soothed them, massaged them, and invigorated
them once again. Throughout the night it continued, activity and
repose, until toward the dawn he fell into a dead sleep, which lasted
until the following morning.
He did not know that he dreamed. He did not consciously remember
any of it. He only knew, as he ate his ample breakfast, that he was
not so thoroughly at peace as he should have been. And he knew
that it was useless to ask the Woman, or one of the Girls.
But the Woman's androids did well by her, it seemed. Maybe he had
better go home to Meg.
"What the square, anyhow?" he said to himself. A little more rest in
his familiar surroundings, and he would be all right. A Bed always
took a lot out of a man. He arose to go.
"Goodbye, dear," the Woman said, as he came to the head of the
main path. She was serene and smiling.
He adjusted his tunic, and smiled in reply. Yes sir, the old world was
in good shape, just like always. He signaled for a Car. The bright
ocean again passed by him, and the broad sands, and he dozed.
The dreams were more importunate, this time. When he awoke, with
a blank start, the Car was cruising aimlessly. He looked around, and
broke into a sweat. There was a button he had to push, somewhere,
there was a handle he had to take hold of. He stammered out "Stop
—now!" and stepped onto the curb. The car sped away, to another
summons. He was before an Emporium, but he did not enter.
Instead, he did an unprecedented thing: he went for a walk, through
the streets of the City. This was not done, and none of the
occupants of the passing cars observed him.
He was really wondering, now. Could something be wrong? This
possibility, with all its full horror, had never entered his mind before;
indeed, he did not even have the conceptions of rightness and
wrongness, and yet there was the inescapable word, "wrong". His
agitation increased. He found himself with the hardly formulated
idea that a school was a place where one learned something, and he
did not know what this could mean.
He thought of the School that he had attended. All the young people
of the District of Fransco attended it: they had been told that there
were other Schools, in other districts, and that they were all the
same. He had believed it, and forgotten about it. What did it matter?
One district was as good as another. He had never travelled. He
knew a Man who had gone to the District of Shasta, but he had not
been interested in hearing about it. He remembered that the Man
had said it was all the same thing, not worth the bother. One had
everything he needed, in his own place. But now it seemed that he
needed something more, something nobody had ever heard of. He
walked on, thinking about the School.
Everybody was born in a House, and kept there till he was weaned,
and could walk. Then he was taken to the School. There he grew up
in an atmosphere of Group Living, and was gradually showed
everything that he needed—everything that there was. The hes and
shes played together; they were instructed in the Ways of Life.
As they grew older, they were taken around the City. They were
showed the places that the Cars could take them; they were showed
how to push the buttons. Of course the robots did a perfect job of
instruction. There were Kitchens, in which one could eat. There were
parks and gardens, in which one could stroll and lounge. There were
Emporiums, in which one could get clothes and things. It was all—as
it was.
When one reached puberty, he was taken from the School, and
given a Pad. There he lived, listening to the soft music that came
from the walls, eating and sleeping. And doing. He selected his
android from an Emporium, and did her as he pleased. She was his
company, the Warmth of his Pad. She shopped in the Emporium for
him, she fixed him cozy little meals, and brought him his pipe or his
cigar. She spread the depilatory cream upon his face in the morning,
and wiped, with so soft a touch, his beard away; and she bathed
him, in the scented waters.
He remained for weeks, for months, in the library. His room was
comfortable, his meals were tasty and well balanced. He lost weight,
he gained continually an alert, aware sense of well-being and
purpose. He was developing a mind, and beginning to know.
Throughout the day he studied consciously, or received hypnotic
instruction; during the night, while his sleep was more keen and
more restful than ever before, the instruction continued. He learned
many things. He became aware of who Aristotle was, and what he
had done. He developed an acquaintance with all the great men and
cultures of the lost lands of Europa. He learned that he lived on the
west coast of Ameru, and that this coast was one large City; he
learned that the once large continent had dwindled greatly in the
disasters, that the ocean waves now poured over the great plains,
and all to the eastward. He felt occasionally a longing to see the
mountains, and the further waters.
He learned and throve. He began to see other figures more
distinctly: once in the corridor he met a Man face to face, and they
smiled and bowed to each other. It had been a small Man, with a
funny beard, and very bright eyes. It had not been like anybody he
had ever seen in the City. But suddenly he knew that he was not like
anybody in the City, and that it could no longer be his home. The
shock of the fact that the City was not everything, that there was
existence, and desirable existence, outside of it, came to him
strongly; but now he was ready for it. When the tumult was over, his
mind was at last born, and he was a human being, ready to aim for
high goals, and to co-operate with destiny.
That night much of a strange nature, called "Sunrise", came to him,
and strange names, faces, and disciplines were vaguely lodged
within him. He awoke with a most definite feeling of readiness, and
with his breakfast he knew, beyond doubt, that "When the disciple is
ready, the Master appears."
When he had finished eating, he left the library, and walked in
thought. How dismal everything was! Nobody knowing, or caring
about anything really important; nobody seeing anything. And
certainly they did not see him: but he saw them very clearly. And
how much was there, still to be seen, all around him? And what was
it, what did it mean? He had to get out, he had to find an answer.
He pushed the nearest button, and slid into the suave black Car that
noiselessly approached. He had never seen a black Car before. He
wondered if his eyes were still playing tricks upon him, if he would
ever see anything aright. Then he dismissed it from his mind.
"Take me out of the City", he said.
There was a slight hesitation; then they were moving, slowly and
quietly, in a northeasterly direction.
It was a long ride, past all the familiar features of the City, multiplied
many fold. At length the Car shuddered slightly, and the virtue
seemed to go out of it in a gentle rush: it stopped, utterly still, and
the silent door slid open with an eloquent finality. He got out, and
the Car seemed to hasten away as from an undesired doom.
But his weird was upon him; he thought so, in the transfixing old
terms; and he turned and beheld an open field, with mountains in
the distance. And it came to him that he had ridden this way before,
and seen nothing but City all around him. He thought then of
enigmatic things that he had heard and read in the library: of how
certain Tibetans rendered themselves invisible, or at least passed
unseen, by shielding their thought waves—by giving out no handle
for perception to grasp. So had this landscape hidden itself, it
seemed: shielded itself from desecration.
Or perhaps there were beings, perhaps there was existence, that
gave continual indication, bristled with handles, as it were: but
handles that could not be grasped or made use of by an organism
insufficiently developed. It seemed more of a truism, the more he
thought of it.
But it did not seem to matter, on this bright new day. He dismissed
the question and stepped forward, into the yielding grass.
What a great thing it was to have a mind, to feel alive on such a
day! He tried to remember how dim, how crippled he had been; it
seemed impossible. Could he have been only one poor, flickering
candle, he who now blazed with the light of a hundred, or a
thousand? Could he have rattled on one cylinder, he who now moved
smoothly and noiselessly on sixteen or twenty? It was too marvelous
for words, or for thoughts.
For a long time he walked, perspiring freely, then puffing, limping
and laboring. It was hot, with no breezes from the sea. An
occasional rill was refreshing, and a glade was cooling: the leaves
rustled gently in the now and then quickened air, and the birds were
sweet with song. But there was no sign of human life. At length he
sat down on a fallen log, and rested.
He sat long, thinking and dozing. The sun was low in the sky when
he arose, and followed some prompting to a ridge not too greatly in
the distance. He had come without provision of any kind, and with
no fear for his welfare: he would see. The ground seemed soft
enough, if he had to sleep there; he took off his shoes and socks,
and enjoyed the cool grass.
He walked on toward the ridge, slowly and confidently, his shoes and
socks in his hand. He had not eaten for many hours, but he did not
seem hungry. Food was not the tremendously important thing that it
used to be. He thought of his old esurience, and smiled. Whatever
his god was, it was not his belly, it was not his body at all. He still
had enough flab to live on for some time without inconvenience, and
it would be better to live on it, than to keep stuffing himself. There
were no women either, and no androids. They were tiresome, and
tiring, things. He sighed almost with contentment.
Soon he crossed the ridge, and saw the smiling farmland in the
valley not far below. This was where the old food supplies had come
from: this had been the life of all but a few, for many centuries.
There was a great peace over it all. With a sense as of treading on
hallowed ground, he descended steadily, and soon came upon a
large and rambling wooden house, unpainted, and comfortable.
Really comfortable, in a human way, not in the sham way of the City.
There was an elderly woman on the porch, serenely rocking. As he
approached, she smiled.
"Welcome, stranger!" she said. "Come on up and rest awhile."
He was glad of the invitation, and he mounted the generous and
solid steps with his shoes and socks still in his hand. He sat down
and redonned them, under her friendly smile.
"It feels good, doesn't it?" she asserted. "The real earth, under real
feet. Maybe you read the poet Hopkins before you got out. I did,
right at the last. One poem has always stuck with me, and especially
this one line of it:
The older man, the father, welcomed him again, and they were soon
seated at the supper table. He noticed that the men ate heartily, and
had yet not an ounce of excess flesh. He rued his own bulk, and ate
but sparingly, only out of politeness. But food had never tasted so
good before.
The two sons were already approaching middle age, and were still
unmarried. This occasioned their mother some concern. But, as she
said, they didn't seem to care, and God or nature could take care of
these things better than people could. There was no use straining.
"And there aren't so many young women around," she mused.
"There aren't many people. Whatever love-making there may be,
there's very little breeding. It's like the City, in that respect. It seems
this just isn't a very good world these days, comparatively speaking,
and people are being held back till it gets better. There seems to be
a sort of a cloud over everything. I don't know. Anyway, we're
contented. At least we have our minds and hearts, and our
patience."
He stayed a week, a month: into the natural influences he vigorously
and gratefully plunged. He helped with the farm work, and grew
lean and hard, and mentally as well as physically strong. He stayed
on, through the winter.
Then, with the spring, his own fertile ground began to burst and
ache, and he was no longer satisfied. He was not nature itself, to
endure unmoved the countless cycles of diversified sameness; he
was rather a flower that faded with a season, a leaf that would soon
fall. He was like a single wave of the vast ocean, and like that wave
he must forever be moving on, questioning.
And so he left the farm very early one morning, and walked north,
as he could tell by the stars. They would not be surprised, and it was
better this way, without farewells. They would know that, for him,
they had served their purpose, and would be glad. And so he walked
north, before sunrise. For this direction he was conscious of no
particular reason; but he felt it to be as good as any other.
He passed a farm or two, skirting them carefully, and breakfasted on
the sunrise alone. It was so beautiful, thus breaking, rose and
golden, over the hills. He remembered the last poet that he had
read, before his deliverance: the great Sidney Lanier. "The Georgia
gold mine," he thought facetiously; and was at once sorry, for his
shallowness. No more would successive suns blaze upon the soft
southern beauty. The warm blue Atlantic waves rolled over the home
of this poet-prophet; whose promise, he fervently hoped, was not
yet drowned. He also would be Lit with the Sun. He stretched out his
arms to the streaming gold, and then walked on vigorously, with a
new purpose not yet defined.
He was getting into ruggeder country, and the going was more
difficult. But yet he felt no inclination to break his fast, or to slacken
his pace. The air was fresh, and good. He climbed around the spur
of a hill, and found himself entering a wild valley with no sign of
human habitation. There was a small stream close by, rippling down
from the solitudes. He went to it, and knelt to drink.
As he arose, two ropes descended upon him, from opposite sides,
and his arms were firmly pinioned. He looked around, and saw two
bearded young men, of not unprepossessing aspect. Each wore
tight-fitting clothing and a peaked hat with a long feather, and was
armed with knife and sword. One of them motioned into the valley.
"Come on, thou varlet!" he said.
They proceeded, and were soon immersed in the rippling and jutting
hills.
Near the head of the valley, and up a hollow to the side, they came
to an expansive and well populated clearing. Many men, bearded
and heavily armed, were lounging about, dressed fancifully, but for
action. There were women also, sturdy and for the most part quite
attractive. He found himself speculating briefly on the fierce joy of
their dalliance in these invigorating wilds. Then his attention was
abruptly drawn ahead, and he was forced to his knees before one
who was obviously the leader.
He was in his middle years, and bore a long flaxen beard and
leonine mane of hair; his eyes were large, and of a piercing but
softly reassuring green. He sat, still and lordly, and surveyed his
captive.
At length: "Arise!"
He obeyed, and stood calmly.
The leader continued, "Thou art doubtless but lately from the City, of
abhorred name. Thou art but little acquainted with the usages of
life. Do not speak! I know 'tis true."
It was so true, and so much beyond him! The meaning was never
clear, and yet, against it, all else was a deeper darkness. But it called
him, and that was sufficient. He must continue, patiently, on the
way.
The walk was pleasant, and the evergreens were soughing gently, as
he passed. Midway in the afternoon he sat down by a convenient
spring, and ate quickly a light meal. As he was resting, a man came
through the trees before him: balding and rather stout, and
apparently approaching the end of middle age. He did not know
whether he cared to talk with this man. But he had little choice, for
he hailed him with a sort of good-natured camaraderie, and came
and sat beside him.
"You may consider me a philosopher," the man announced; "that is,
in the fine old sense, a lover of wisdom. I don't think that will
frighten you away," he chuckled. "I think I can see that you agree
with Socrates: that you consider an unexamined life to be a life that
is not worth living. Is this correct?"
He replied that it was, and that he was a seeker of wisdom, and
hoped one day to prove to be a lover of it—after he had found it.
The philosopher smiled, and continued, "Perhaps it is best to be a
lover of the search; perhaps, indeed, the search itself is the greatest
wisdom. This used to be considered a platitude," he laughed, "when
education was more wide-spread in the world. But I have never
found anything bright and brand new that matches it. I do not want
to be one of those who 'give to dust that is a little gilt more laud
than gilt o'erdusted'. How about you?"
He smiled agreement. He was beginning somewhat to like this man:
but still he could not respect him, either as an embodiment of
wisdom or as a seeker of it. His mind seemed only clever, and rather
lazy and complacent with its cleverness: it seemed quite incapable of
any really deep probing, or high flight. This was not his idea of a
philosopher.
The object of this scrutiny seemed somewhat to sense its import,
and to shrug it off.
"I could tell it at a glance," he said. "You're one of the most
intelligent men I've ever seen escape from that monstrosity of a City.
Let me congratulate you! It's a terrible thing to live like that.
"One immense mechanized mass! One big idiot's delight, full of
nothing but idiots, or morons at best. Everybody "happy": food,
shelter and sex all taken care of, and real human contact at a
minimum: a true earthly paradise. A paradise for morons, that is, for
people who really prefer to live worse than hogs. God bless the dear
technologists, who keep it going: they as stupid as the majority, of
course, just morons with a little mechanical know-how, as the
phrase was. And bless whatever powers there are, for the library,
and the chance to escape!
"I don't know how it came about, but there's something behind it.
Just before the poor little fools could blow themselves up, the
Disasters hit them: and while they were still traumatized, this system
began to take care of them. It's a fine thing, I guess, for those that
aren't capable of a life worth living. And for those that are, too: it
seems to take hold of them at just the right time. It seems that it
gives everyone just what he is best fitted for, and then lets him go.
"It never really let go of me—or got rid of me. I alternate, from city
to country: read myself to a standstill, and then travel awhile. It's
always pleasant, up here. It's like the coast: the seasons don't
change anymore. That is, there aren't any seasons—just hints of
them. But maybe you know that by now. Ah—yes. I guessed as
much. You look like a man that has been out long enough to—well,
to look like a man.
"I wonder how it will end? The birth-rate's way down, and seems to
continue decreasing, even in the country. Maybe the race is
gradually dying out: evolution getting rid of an unfit species. But I
wouldn't expect it to be so gentle about it.
"The more I think about it, the better I see what an infinite amount
I've got to learn. Another platitude: Newton picking up pebbles on
the sea-shore. Maybe the craze for sheer novelty is one of the things
that made this mess. I don't know. But I think that there is such a
thing as truth, and that it doesn't adapt itself to conditions:
conditions have to adapt themselves to it. Do you agree? Yes, I
thought so. I think I'll have to be heading back to the library in a few
days. I've seen enough this trek.
"There seems to be a guardian angel, somehow, if you believe in
that. The explanation's probably a purely natural one. But people
come out and live as they like to, with no hindrance, and they
prosper. They do a little simple farming, and always have bumper
crops. The weather and the wild animals never hurt them, and they
never hurt each other. The ones that like to fight do it, but only with
swords and knives, and nobody ever seems to get killed. All the
literature and art of the world is preserved, for those that want it: as
many copies as demanded. Sometimes I bring copies of books with
me. It helps, to read them out here. Nature's a lot vaster and more
wonderful than we know.
"Everything seems to be taken care of. Nobody lives in want or fear
anymore. Except," he smiled ruefully, "want of understanding, and
fear of death. But we can take things philosophically, to use an old
popular expression."
The philosopher paused awhile, thinking, observing his perplexing
companion. He could not make him out. Presently he returned to his
long-standing provisional solution for all problems.
"Well, why don't you come back to the library with me? Tramping
around out here is all right for a while, it relaxes you and keeps you
in touch with things; but meanwhile, time flies. Shall we go?"
"I think not," the bearded patriarch replied. "The usefulness of books
is all but exhausted for me. And even the greatest and fullest truth,
set down in a book, I think must be inadequate. It's not an
intellectual thing I seek."
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com