0% found this document useful (0 votes)
23 views5 pages

Programmatic PDF Signing in JavaScript

The document provides a guide to various JavaScript samples in the Adobe Acrobat SDK, including how to programmatically sign a PDF, add toolbar buttons, manage annotations, and convert date formats. Each sample includes a description, usage instructions, and necessary requirements for execution. The samples demonstrate functionalities like digital signatures, annotation management, and date conversions within PDF documents.

Uploaded by

Roman Corrales
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Programmatic PDF Signing in JavaScript

The document provides a guide to various JavaScript samples in the Adobe Acrobat SDK, including how to programmatically sign a PDF, add toolbar buttons, manage annotations, and convert date formats. Each sample includes a description, usage instructions, and necessary requirements for execution. The samples demonstrate functionalities like digital signatures, annotation management, and date conversions within PDF documents.

Uploaded by

Roman Corrales
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Adobe Acrobat SDK JavaScript Samples

Guide to SDK Samples AddSignature 35

AddSignature
Location
JavaScript/Samples/OutsidePDF

Description
Shows how to programmatically sign a PDF document using a predefined digital ID file. The JavaScript
code includes all the digital signature information used to sign the document, except the path and
password for the digital ID file.

To use this sample file, copy the [Link] file to the JavaScript folder under Acrobat, or to
the user's JavaScript folder. When you restart Acrobat you should see a new item Add My Signature
under the Advanced menu.

When you are ready to sign a PDF document, click the newly added Add My Signature menu item. After
you input the platform-independent path and the password through a dialog box, the program creates a
digital signature field in the top left corner. The path and password are valid in an Acrobat session, so you
can continue to sign more documents in the session without the input dialog box. If you change the
JavaScript code to specify the path and password for the digital ID file to be used, then when you click the
menu item, the program will automatically sign PDF documents without requiring the UI. A digital
signature file ( [Link] ) is provided with the sample. To use it, put it in a folder, and specify the proper
DIpath (for example /C/[Link]). The password is "testpassword".

It is also possible to execute the JavaScript code to sign a PDF document from another JavaScript program,
or from a plug-in, Visual Basic (using interapplication communication), or Visual C++ program through the
function ExecuteThisScript. See the source code for more information.

Beginning with Acrobat 7.x, in order to execute the security-restricted method through a menu event in
this sample, the item labeled Enable Menu Items JavaScript Execution Privileges under Edit > Preferences
> General > JavaScript must be checked. An alternative way is to wrap up the security methods used in
the code through a trusted function. For details and examples, see [Link] in the JavaScript
for Acrobat API Reference.

Note: Requires Reader-enabled PDF document to run in Adobe Reader.


Adobe Acrobat SDK JavaScript Samples
Guide to SDK Samples AddToolButton 36

AddToolButton
Location
JavaScript/Samples/UI

Description
This folder level JavaScript sample, [Link], demonstrates how to add a toolbar button with the
user-specified icon image file and JavaScript code.

Usage
The sample will add a menu item of Add Tool Button... under the Tools menu. Click it to display a JSADM
dialog box. You must input a device-independent path to specify a PDF or image file (e.g. JPEG file) as an
icon image file. The image should have a size of 20 X 20 pixels. Two sample image files, [Link]
and [Link], are included in the sample folder.
Adobe Acrobat SDK JavaScript Samples
Guide to SDK Samples AnnotSample 37

AnnotSample
Location
JavaScript/Samples/OutsidePDF

Description
Folder level JavaScript code to exercise the annotation APIs useful in reviewing workflow. It can be used
with a rights-enabled PDF document in Adobe Reader as well as regular PDF documents in Acrobat.

Usage
This folder JavaScript file adds a new menu item under the Tools menu. It will trigger a JSADM dialog box
to show the following functions:
● Set annotations as read only or editable
● Import annotations from a local FDF file
● Export all annotations to a local FDF file
● Export editable annotations to a local FDF file

You can try the functions while creating or modifying annotations in the PDF document.

To run the sample, you need to specify a path in the dialog box for a data repository in your environment.
The path must be a safe path and in a platform-independent format, such as
/c/test/[Link].

A test file, [Link], with Reader-enabled usage rights is provided in the sample folder.

Note: Requires Reader-enabled PDF document to run in Adobe Reader.


Adobe Acrobat SDK JavaScript Samples
Guide to SDK Samples AnnotatedWords 38

AnnotatedWords
Location
JavaScript/Samples/OutsidePDF

Description
This script returns to the console the words covered by highlight annotations. The script can be adapted to
output the text elsewhere, such as to a file. It can also be edited to include other text-related annotations,
such as underline or cross-out.

This script is limited to single-column, left-to-right, top-to-bottom, horizontal, non-overlapping text.


Vertical text, text bound to a shape, right-to-left text, etc., may not work.

Annotated text is reported annotation by annotation in the order that the annotations were applied to the
doc (appear in the annotations array), not in reading order or any other word order on the page.

This script uses [Link]() to obtain its results. As such, it cannot report partial words
under an annotation. Instead, any word that is partially covered by an annotation is included in the output.
Additionally, line spacing, document origin, font size and other factors may affect how closely an
annotation's quads and a word's quads overlap. For some documents, the results may not be accurate.
Please see in-line comments for more information.

Usage
This JavaScript adds a menu item to the Comments menu: ACROSDK: Copy Highlighted Text to JS Console.
The script will work on the active document and output words covered by highlight annotations to the
console in a page-by-page list.

Note: Requires Reader-enabled PDF document to run in Adobe Reader.


Adobe Acrobat SDK JavaScript Samples
Guide to SDK Samples ConvertTime 39

ConvertTime
Location
JavaScript/Samples/InsidePDF

Description
[Link] is a JavaScript sample that demonstrates how to convert the PDF date format to a JavaScript
date object and back again. It also shows how to display the JavaScript date in various formats using utility
methods.

Usage
There are three operation groups with instructions. Click the buttons and check results shown in text
fields. You can convert the PDF date to a JavaScript date object with various formats, input your own date
in the PDF format to check the conversion result, and convert the JavaScript date back to the PDF format.

Common questions

Powered by AI

The AnnotSample script allows modifications and management of annotations, such as setting them to read-only or exporting them for archival. Meanwhile, the AnnotatedWords script provides a mechanism to extract text covered by these annotations, offering a detailed view of what's highlighted or noted. Together, they provide a comprehensive toolkit for managing and reviewing documents; AnnotSample edits and controls annotations, whereas AnnotatedWords facilitates analysis of annotated sections. This combination supports document reviews, especially in workflows involving extensive annotation analysis and documentation .

Adding a menu item in Adobe Acrobat via JavaScript significantly enhances workflow automation by allowing scripted actions to be easily accessible through the UI. This feature can automate repetitive tasks such as batch-processing PDF conversions, applying standardized annotations, or executing complex scripts with a single click. Potential use cases include legal document processing, educational material preparation, or streamlining digital signature applications across multiple documents, thereby reducing manual errors and improving efficiency .

The AddToolButton JavaScript sample enables users to add a custom toolbar button in Acrobat. This involves adding a menu item under the Tools menu that triggers a JSADM dialog box, requiring a device-independent path for a PDF or image file to be used as the icon. The image, ideally a JPEG, must be 20x20 pixels in size. Sample images are provided in the sample folder for convenience. This customization allows unique UI elements to be created and tailored for specific workflows .

The ConvertTime JavaScript sample allows conversion between PDF date formats and JavaScript date objects. Users can convert a PDF date into various JavaScript formats, input dates in PDF format for conversion checking, and re-convert JavaScript dates back to PDF format. The sample includes three operation groups, each with specific buttons for triggering these conversions and displaying results in text fields. This aids in integrating dates within scripts that need synchronization or conversion between formats .

In a networked environment with multiple users, challenges in executing the AddSignature process include managing secure access to the digital ID file and ensuring the confidentiality of the digital signature password. Network configurations must prevent unauthorized access to the digital ID path and password, possibly requiring encryption. Scalability across different user permissions and session management for automation without repeated input can also complicate setup. Implementing robust network security protocols and centralized user management could mitigate these issues .

When executing security-restricted methods through JavaScript in Adobe Acrobat, it's essential to enable 'Menu Items JavaScript Execution Privileges' in Acrobat's preferences. Alternatively, wrapping the security methods in a trusted function using app.trustedFunction can provide the necessary permissions. Readers should only execute scripts from trusted sources due to potential security vulnerabilities. Additionally, the document must be Reader-enabled to run in Adobe Reader, ensuring compatibility with restricted operations .

When using the AnnotatedWords script on documents with complex text layouts, considerations should include the text's orientation and column structure, as the script primarily targets single-column, left-to-right, horizontal text. It may not work correctly with vertical or multi-column layouts, or texts bound to shapes. Careful pre-processing to verify the text’s format and potential script adjustments for different layout types or expanding annotation recognition is recommended to improve accuracy .

The AnnotSample JavaScript code demonstrates functionalities key to annotation workflows, such as setting annotations to read-only or editable, importing annotations from a local FDF file, and exporting all or editable annotations to a local FDF file. These functions are accessed via a menu item added under the Tools menu, which triggers a JSADM dialog box. Users can execute these functions by specifying the path to a data repository in a platform-independent format. This sample requires a Reader-enabled PDF to run in Adobe Reader .

To programmatically add a digital signature to a PDF document using Adobe Acrobat SDK, the sdkAddSignature.js file must be copied to the Acrobat JavaScript folder. After restarting Acrobat, the "Add My Signature" menu item becomes available. Users input the path and password for the digital ID file through a dialog box. The signature field is created in the document, and these credentials stay valid for the session. By embedding the path and password directly in the script, the process can be fully automated without any UI interaction. Requirements include a Reader-enabled PDF document and checking the 'Enable Menu Items JavaScript Execution Privileges' option in Acrobat preferences if security-restricted methods are involved .

The AnnotatedWords script can only extract words under highlight annotations in PDFs with single-column, left-to-right, top-to-bottom text. It cannot report partial words under annotations, and may be affected by differences in line spacing, document origin, or font size. For improvements, the script could be enhanced to recognize multi-column layouts or right-to-left text, and to report partial words. Another improvement could involve refining the algorithm to consider annotation overlaps and adjusting for font and spacing variations for more accuracy .

You might also like