Programming Acrobat JavaScript Using Visual Basic

Content Preview
This HTML preview only show 5 first pages of the document. Please download to read full content.

Adobe Acrobat 7.0.5Programming Acrobat JavaScript Using Visual Basic
October 21, 2005

Adobe Solutions Network — http://partners.adobe.com

Copyright 2005 Adobe Systems Incorporated. All rights reserved. NOTICE: All information contained herein is the property of Adobe Systems Incorporated. No part of this publication (whether in hardcopy or electronic form) may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of the Adobe Systems Incorporated. PostScript is a registered trademark of Adobe Systems Incorporated. All instances of the name PostScript in the text are references to the PostScript language as defined by Adobe Systems Incorporated unless otherwise stated. The name PostScript also is used as a product trademark for Adobe Systems’ implementation of the PostScript language interpreter. Except as otherwise stated, any reference to a “PostScript printing device,” “PostScript display device,” or similar item refers to a printing device, display device or item (respectively) that contains PostScript technology created or licensed by Adobe Systems Incorporated and not to devices or items that purport to be merely compatible with the PostScript language. Adobe, the Adobe logo, Acrobat, the Acrobat logo, Acrobat Capture, Distiller, PostScript, the PostScript logo and Reader are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. Apple, Macintosh, and Power Macintosh are trademarks of Apple Computer, Inc., registered in the United States and other countries. PowerPC is a registered trademark of IBM Corporation in the United States. ActiveX, Microsoft, Windows, and Windows NT are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Verity is a registered trademark of Verity, Incorporated. UNIX is a registered trademark of The Open Group. Verity is a trademark of Verity, Inc. Lextek is a trademark of Lextek International. All other trademarks are the property of their respective owners. This publication and the information herein is furnished AS IS, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies, makes no warranty of any kind (express, implied, or statutory) with respect to this publication, and expressly disclaims any and all warranties of merchantability, fitness for particular purposes, and noninfringement of third party rights.

Programming Acrobat JavaScript Using Visual Basic
Acrobat 7.0 provides a rich set of JavaScript programming interfaces that are designed to be used from within the Acrobat environment. It also provides a mechanism (known as JSObject) that allows external clients to access the same functionality from environments such as Visual Basic. This document gives you the information you need to get started using the extended functionality of JavaScript from a Visual Basic programming environment. It provides a set of examples to illustrate the key concepts.

What is JSObject?
In precise terms, JSObject is an interpretation layer between an OLE Automation client such as a Visual Basic application and the JavaScript functionality provided by Acrobat. From a programmer’s point of view, the end result is that programming JSObject from a Visual Basic environment is quite similar to programming in JavaScript using the Acrobat console.

Getting Started
The following steps get you set up to run the examples: 1. Install Acrobat 7.0 and Visual Basic .NET, since both are required for the examples in this document. 2. Open a new Visual Basic.NET project. That gets you started with a blank form and project workspace. 3. To access the Acrobat Automation APIs, including JSObject, you need to add a reference to Acrobat’s type library. From the UI, select Project > Add Reference, then the COM tab, and from the list of available references, click on the item labeled “Adobe Acrobat 7.0 Type Library.” Click Select. Click OK.

Programming Acrobat JavaScript Using Visual Basic

3

Programming Acrobat JavaScript Using Visual Basic
A Simple Example

A Simple Example
This example describes the bare minimum required to display “Hello, Acrobat!” in Acrobat’s JavaScript console. 1. Bring up the source code window for this form by selecting View > Code from the UI. 2. Select (Form1 Events) from the selection box in the upper left corner of that window. The selection box in the upper right shows all the functions available to the Form object. 3. Select Load from that box, which creates an empty function stub. The Form’s Load function is called when the Form is first displayed, so it’s a good place to add the initialization code. This program uses some global variables for data that are required for its lifetime, and initializes them in the Form1_Load routine.

4

Programming Acrobat JavaScript Using Visual Basic

Programming Acrobat JavaScript Using Visual Basic
A Simple Example

EXAMPLE 1

“Hello, Acrobat!”

Dim gApp As Acrobat.CAcroApp Dim gPDDoc As Acrobat.CAcroPDDoc Dim jso As Object Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load gApp = CreateObject(“AcroExch.App”) gPDDoc = CreateObject(“AcroExch.PDDoc”) If gPDDoc.Open(“c:\adobe.pdf”) Then jso = gPDDoc.GetJSObject jso.console.Show jso.console.Clear jso.console.println (“Hello, Acrobat!”) gApp.Show End If End Sub

Note that you need a file called adobe.pdf at the root level of your C: drive. With this code in place, the Visual Basic program attaches to Acrobat’s Automation interface using the CreateObject call, then shows the main window using the App object’s Show command. You may have a few questions after studying the code fragment. For example, why is jso declared as an Object, while gApp and gPDDoc are declared as types found in the Acrobat type library? Is there a real type for JSObject? The answer is no, JSObject does not appear in the type library, except in the context of the CAcroPDDoc.GetJSObject call. The COM interface used to export JavaScript functionality through JSObject is known as an IDispatch interface, which in Visual Basic is more commonly known simply as an “Object” type. The upshot of this is that the methods available to the programmer are not as well-defined as we would like. For example, you might be surprised to learn that if you replace the call to
jso.console.clear

with
jso.ThisCantPossiblyCompileCanIt(“Yes it can!”)

the compiler happily compiles the code, but fails rudely at run time. Since Visual Basic has no type information for JSObject, Visual Basic does not know if a particular call is even syntactically valid until runtime, and will compile any function call to a JSObject. For that reason, the programmer must rely on documentation to know what functionality is available through the JSObject interface. The Acrobat JavaScript Scripting Reference, which is available from http://partners.adobe.com/links/acrobat, is indispensable as you delve deeper into the mysteries of JSObject. You may also wonder why it is necessary to open a PDDoc before creating a JSObject. Running the program shows that no document appeared onscreen, and showing the JavaScript console should be possible without a PDDoc in hand. The answer is that JSObject is designed to work closely with a particular document, since most of the available

Programming Acrobat JavaScript Using Visual Basic

5

This Programming Acrobat JavaScript Using Visual Basic PDF ebook is available FREE at http://www.adobe.com website, We only collect information from the website, we have no affiliation with the author, website and brand, we are also not responsible for the content of PDF document. If you are owner of the site of any links provided on this site and wants to remove your link from our site then please Contact us with our Contact form or read our disclaimer here.




Most Viewed PDF Download Post on Javascript Category:
Recently PDF Download Post on Programming, Technology Pdf Ebooks Category: