Javascript adobe acrobat reader

Acrobat-PDFL SDK: JavaScript Development¶

JavaScript was created to offload web page processing from a server onto a client in web-based applications. Acrobat extends the core language by adding new objects and their accompanying methods and properties, to the JavaScript language. These Acrobat-specific objects enable a developer to manage document security, communicate with a database, handle file attachments, manipulate a PDF file so that it behaves as an interactive, web-enabled form, and so on. Because the Acrobat-specific objects are added on top of core JavaScript, you still have access to its standard classes, including Math , String , Date , and RegExp .

PDF documents have great versatility since they can be displayed both within the Acrobat software as well as a web browser. Therefore, it is important to be aware of the differences between JavaScript used in a PDF file and JavaScript used in a web page:

  • JavaScript in a PDF file does not have access to objects within an HTML page. Similarly, JavaScript in a web page cannot access objects within a PDF file.
  • In HTML, JavaScript is able to manipulate such objects as Window . JavaScript for Acrobat cannot access this particular object but it can manipulate PDF-specific objects.

Most people know Acrobat as a medium for exchanging and viewing electronic documents easily and reliably, independent of the environment in which they were created; however, Acrobat provides far more capabilities than a simple document viewer.

You can enhance a PDF document so that it contains form fields to capture user-entered data as well as buttons to initiate user actions. This type of PDF document can replace existing paper forms, allowing employees within a company to fill out forms and submit them via PDF files, and connect their solutions to enterprise workflows by virtue of their XML-based structure and the accompanying support for SOAP-based web services.

Читайте также:  Java launcher как работать с ним

Acrobat also contains functionality to support online team review. Documents that are ready for review are converted to PDF. When a reviewer views a PDF document in Acrobat and adds comments to it, those comments (or annotations). constitute an additional layer of information on top of the base document. Acrobat supports a wide variety of standard comment types, such as a note, graphic, sound, or movie. To share comments on a document with others, such as the author and other reviewers, a reviewer can export just the comment “layer” to a separate comment repository.

In either of these scenarios, as well as others that are not mentioned here, you can customize the behavior of a particular PDF document, implement security policies, interact with databases and web services, and dynamically alter the appearance of a PDF document by using JavaScript. You can tie JavaScript code to a specific PDF document, a particular page within a PDF document, or a form field or button in a PDF file. When an end user interacts with Acrobat or a PDF file displayed in Acrobat that contains JavaScript, Acrobat monitors the interaction and executes the appropriate JavaScript code.

Not only can you customize the behavior of PDF documents in Acrobat, you can customize Acrobat itself. In earlier versions of Acrobat (prior to Acrobat 5), this type of customization could only be done by writing Acrobat plug-ins in a high-level language like C or C++. Now, much of that same functionality is available through Acrobat extensions to JavaScript. You will find that using JavaScript to perform a task such as adding a menu to Acrobat’s user interface is much easier than writing a plug-in.

Using Acrobat Pro, you can create batch sequences for processing multiple documents, processing within a single document, processing for a given page, and processing for a single form field. For batch processing, it is possible to execute JavaScript on a set of PDF files, which enables tasks such as extracting comments from a comment repository, identifying spelling errors, and automatically printing PDF files.

Читайте также:  Дополнительные модули для php

JavaScript for Acrobat API Reference¶

The companion document to this document is the Acrobat JavaScript API Reference. In addition to a list of APIs, it provides details about security restrictions placed on some of the methods.

These features are of particular importance:

  • The quick bar. In the Acrobat JavaScript API Reference, each object, property and method has a quick bar, a one-row table of icons that provides a summary of the item’s availability and usage recommendations. Many lost hours of time can be avoided by paying attention to this quick bar.
  • Privileged context. This guide contains detailed information on executing JavaScript in a privileged context beyond that provided in the Acrobat JavaScript API Reference, see Privileged versus non-privileged context.
  • Safe path. Acrobat 6.0 introduced the concept of a safe path for JavaScript methods that write data to the local hard drive based on a path passed to it by one of its parameters. Generally, when a path is judged to be not safe, a NotAllowedError exception is thrown. See the Acrobat JavaScript API Reference for more information about safe paths.

Many sample scripts presented in this guide reference the local file system. These scripts generally use the path «/c/temp/» , which is a safe path.

Object summary¶

The Acrobat extension to core JavaScript defines many objects that allow your code to interact with the Acrobat application, a PDF document, or form fields within a PDF document. This section introduces you to the primary objects used to access and control the application and document, the development environment itself, and general-purpose JavaScript functionality.

Below is a short listing of some of the main objects used in the document and in the sample files. A brief description of each of the objects follow the table.

Читайте также:  Python count letter in string

Источник

Добавление отладки JavaScript

Отладчик JavaScript в Acrobat позволяет построчно просмотреть код, задать точки останова и проверить переменные, используя диалоговое окно отладчика.

Чтобы включить отладчик JavaScript, перейдите к меню «Редактирование» > «Установки» > «JavaScript», а затем установите флажок «Включать отладчик JavaScript после перезагрузки Acrobat».

Чтобы запустить отладчик, выберите «Инструменты» > «JavaScript» > «Отладчик».

Управление сценариями JavaScript в документе

Диалоговое окно «Сценарии JavaScript в документе» позволяет добавлять, редактировать или удалять сценарии в текущем документе.

Чтобы открыть данное диалоговое окно, выберите «Инструменты» > «JavaScript» > «Сценарии JavaScript в документе».

Редактор JavaScript

С помощью редактора JavaScript можно создавать и редактировать сценарии.

Чтобы открыть редактор, выберите «Инструменты» > «JavaScript» > «Все сценарии JavaScript».

Действия с документом и JavaScript

Отдельный сценарий JavaScript можно связать с конкретным действием с документом. Такой сценарий выполняется, когда инициируется соответствующее действие.

Чтобы открыть диалоговое окно «Действия с документом», выберите «Инструменты» > «JavaScript» > «Действия с документом».

Выберите действие, а затем щелкните «Изменить», чтобы добавить сценарий к выбранному действию.

Настройка документов PDF с помощью JavaScript

Использование JavaScript — один из самых простых и наиболее мощных способов настройки файлов PDF. Основанный на JavaScript версии 1.5 стандарта ISO-16262 (ранее известной как ECMAScript) JavaScript в программном обеспечении Adobe Acrobat реализует объекты, методы и свойства, которые позволяют управлять файлами PDF, создавать управляемые базами данных файлы PDF, изменять внешний вид файлов PDF и многое другое. Код JavaScript в Acrobat можно связать с конкретным документом PDF, страницей, полем или кнопкой в пределах этого документа либо с полем или кнопкой в файле PDF и даже с действием пользователям.

JavaScript полезен для XML-форм. JavaScript делает возможными автоматическую обработку форм, обмен данными с веб-ресурсами и базами данных, комментирование и другие возможности пользовательского интерфейса. Из файлов PDF, созданных с помощью инструментов Acrobat и Adobe LiveCycle, данные можно извлекать в пользовательские схемы как XML-код. Приложения, написанные на Java и других языках, легко интегрируют Acrobat с веб-службами с помощью протокола SOAP.

Связанные материалы

Источник

Оцените статью