Developing Acrobat Applications Using JavaScript - Adobe Inc.

Developing Acrobat Applications Using JavaScript

2/1/21 Adobe, Inc.

Adobe Acrobat SDK Documentation. ? 2020 Adobe Inc. All rights reserved.

If this guide is distributed by Adobe with software that includes an end user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license. Except as permitted by any such license, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe. Please note that the content in this guide is protected under copyright law even if it is not distributed with software that includes an end user license agreement.

This guide is governed by the Adobe Acrobat SDK License Agreement and may be used or copied only in accordance with the terms of this agreement. Except as permitted by any such agreement, no part of this guide may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, recording, or otherwise, without the prior written permission of Adobe. Please note that the content in this guide is protected under copyright law.

Please remember that existing artwork or images that you may want to include in your project may be protected under copyright law. The unauthorized incorporation of such material into your new work could be a violation of the rights of the copyright owner. Please be sure to obtain any permission required from the copyright owner.

Any references to company names, company logos, and user names in sample material or sample forms included in this documentation and/or software are for demonstration purposes only and are not intended to refer to any actual organization or persons.

Adobe, the Adobe logo, Acrobat, Distiller, and Reader are either registered trademarks or trademarks of Adobe the United States and/or other countries.

All other trademarks are the property of their respective owners.

Notice to U.S. Government End Users. The Software and Documentation are "Commercial Items," as that term is defined at 48 C.F.R. ?2.101, consisting of "Commercial Computer Software" and "Commercial Computer Software Documentation," as such terms are used in 48 C.F.R. ?12.212 or 48 C.F.R. ?227.7202, as applicable. Consistent with 48 C.F.R. ?12.212 or 48 C.F.R. ??227.7202-1 through 227.7202-4, as applicable, the Commercial Computer Software and Commercial Computer Software Documentation are being licensed to U.S. Government end users (a) only as Commercial Items and (b) with only those rights as are granted to all other end users pursuant to the terms and conditions herein. Unpublished-rights reserved under the copyright laws of the United States. Adobe Inc., 345 Park Avenue, San Jose, CA 95110-2704, USA

Adobe Acrobat DC SDK

Acrobat JS Developer Guide

3

List of Examples ........................................................................................................................... 9

1 Introduction ............................................................................................................................... 11

Reading the JavaScript for Acrobat API Reference..............................................................................................................12 Object summary ...........................................................................................................................................................................12

app............................................................................................................................................................................................... 13 Doc ..............................................................................................................................................................................................13 dbg ..............................................................................................................................................................................................14 console ....................................................................................................................................................................................... 14 global..........................................................................................................................................................................................14 util ................................................................................................................................................................................................ 14 dialog..........................................................................................................................................................................................14 security....................................................................................................................................................................................... 14 SOAP ...........................................................................................................................................................................................15 search .........................................................................................................................................................................................15 event ........................................................................................................................................................................................... 15 JavaScript applications...............................................................................................................................................................15

2 Tools ........................................................................................................................................... 18

Using the JavaScript Debugger console..............................................................................................................................18 Opening the console ............................................................................................................................................................18 Executing JavaScript.............................................................................................................................................................18 Formatting code.....................................................................................................................................................................19 Enabling JavaScript ...............................................................................................................................................................19 Debugging with the JavaScript Console .......................................................................................................................20

Using a JavaScript editor ...........................................................................................................................................................21 Specifying the default JavaScript editor ..............................................................................................................................21 Using an external editor.............................................................................................................................................................22

Additional editor capabilities ............................................................................................................................................22 Specifying additional capabilities to your editor .......................................................................................................23 Saving and closing a file with a syntax error................................................................................................................24 Using the Debugger with Acrobat Reader DC...................................................................................................................24 Enabling the JavaScript Debugger ........................................................................................................................................25 JavaScript Debugger...................................................................................................................................................................26 Main groups of controls.......................................................................................................................................................27 Debugger View windows....................................................................................................................................................27 Debugger buttons .................................................................................................................................................................28 Debugger Scripts window ..................................................................................................................................................30 Call Stack list ............................................................................................................................................................................31 Inspect details window ........................................................................................................................................................32

Coding styles and breakpoints ...................................................................................................................................34 Listing breakpoints .........................................................................................................................................................34 Using conditional breakpoints ...................................................................................................................................34 Starting the Debugger .........................................................................................................................................................35 Final notes ................................................................................................................................................................................36

3 JavaScript Contexts in Acrobat DC........................................................................................... 37

The concept of a JavaScript event .........................................................................................................................................37 About contexts..............................................................................................................................................................................38

Folder level ...............................................................................................................................................................................39 Document level ......................................................................................................................................................................39 Page level..................................................................................................................................................................................40

Adobe Acrobat DC SDK

Acrobat JS Developer Guide

4

Field level ..................................................................................................................................................................................41 Privileged versus non-privileged context ...........................................................................................................................41

Executing privileged methods in a non-privileged context...................................................................................42 Executing privileged methods through the menu....................................................................................................43 Executing privileged methods in a certified document ..........................................................................................45

4 Creating and Modifying PDF Documents ................................................................................ 46

Creating and modifying PDF files...........................................................................................................................................46 Combining PDF documents...............................................................................................................................................47 Combining and extracting files.........................................................................................................................................47 Creating file attachments....................................................................................................................................................49 Cropping and rotating pages ............................................................................................................................................51 Cropping pages................................................................................................................................................................51 Rotating pages..................................................................................................................................................................52 Extracting, moving, deleting, replacing, and copying pages ................................................................................52 Adding watermarks and backgrounds...........................................................................................................................54

Converting PDF documents to XML format .......................................................................................................................55

5 Print Production ........................................................................................................................ 56

Setting print options...................................................................................................................................................................56 Printing PDF documents............................................................................................................................................................57

Silent printing..........................................................................................................................................................................59 Printing comments and forms ..........................................................................................................................................59 Booklet printing......................................................................................................................................................................59 Setting advanced print options........................................................................................................................................60

Specifying output settings ...........................................................................................................................................60 Specifying marks and bleeds.......................................................................................................................................61 Setting PostScript options............................................................................................................................................61 Setting font options........................................................................................................................................................61

6 Using JavaScript in Forms ......................................................................................................... 63

Forms essentials............................................................................................................................................................................63 About PDF forms....................................................................................................................................................................63 Elements of Acrobat DC forms....................................................................................................................................63 Guidelines for creating a new form...........................................................................................................................64 Creating Acrobat DC form fields.......................................................................................................................................64 Setting Acrobat DC form field properties .....................................................................................................................66 Field properties ................................................................................................................................................................66 Button fields ......................................................................................................................................................................67 Check box fields ...............................................................................................................................................................69 Combo box fields.............................................................................................................................................................70 List box fields.....................................................................................................................................................................74 Radio button fields..........................................................................................................................................................76 Signature fields.................................................................................................................................................................77 Text fields............................................................................................................................................................................78 Validation scripts..............................................................................................................................................................79 Calculation script .............................................................................................................................................................80

Task-based topics .........................................................................................................................................................................81 Highlighting required form fields ....................................................................................................................................81 Making a form fillable...........................................................................................................................................................82 Setting the hierarchy of form fields.................................................................................................................................82 Creating forms ........................................................................................................................................................................83

Adobe Acrobat DC SDK

Acrobat JS Developer Guide

5

Positioning form fields...................................................................................................................................................83 Duplicating form fields ..................................................................................................................................................84 Creating multiple form fields ......................................................................................................................................85 Defining the tabbing order ................................................................................................................................................85 Defining form field calculation order .............................................................................................................................86 Making PDF forms web-ready ...........................................................................................................................................86 Creating a submit button .............................................................................................................................................87 Creating a reset form button.......................................................................................................................................87 Defining CGI export values ..........................................................................................................................................87 Importing and exporting form data................................................................................................................................87 Emailing completed forms .................................................................................................................................................87 Use date objects .....................................................................................................................................................................88 Date arithmetic .......................................................................................................................................................................89 Defining global variables in JavaScript ..........................................................................................................................90 Enable the global object security policy .................................................................................................................90 Setting and getting a global variable.......................................................................................................................91 Deleting global variables ..............................................................................................................................................91 Making global variables persistent ...........................................................................................................................91 Querying an Acrobat DC form field value in another open form...................................................................92 Global object security policy .......................................................................................................................................92 Intercepting keystrokes in an Acrobat DC form .........................................................................................................93 Constructing custom colors ...............................................................................................................................................93 Prompting the user for a response..................................................................................................................................93 Fetching an URL from JavaScript .....................................................................................................................................93 Creating special rollover effects .......................................................................................................................................94 Global submit ..........................................................................................................................................................................94 Making forms accessible............................................................................................................................................................95 Text-to-speech ........................................................................................................................................................................95 Tagging annotations ............................................................................................................................................................96 Document metadata.............................................................................................................................................................96 Short description....................................................................................................................................................................97 Setting tab order ....................................................................................................................................................................97 Reading order..........................................................................................................................................................................97 Using JavaScript to secure forms............................................................................................................................................97

7 Review, Markup, and Approval ..............................................................................................100

Working with comments using JavaScript....................................................................................................................... 100 Annotation types ................................................................................................................................................................ 100 Getting annotation data................................................................................................................................................... 101 Adding comments with JavaScript............................................................................................................................... 102 Setting comment properties .......................................................................................................................................... 102

Online collaboration essentials ............................................................................................................................................ 102 Reviewing documents with additional usage rights ............................................................................................. 103 Emailing PDF documents................................................................................................................................................. 104 JavaScript-based collaboration driver......................................................................................................................... 104 Spell-checking in comments and forms ..................................................................................................................... 106 Setting spelling preferences..................................................................................................................................... 106 Adding words to a dictionary................................................................................................................................... 106 Approval................................................................................................................................................................................. 106

Managing comments............................................................................................................................................................... 106 Selecting, moving, and deleting comments ............................................................................................................. 107

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download