Recently in JavaScript Category

Share

The Acrobat 9.1 SDK documentation is here!

The Acrobat 9.1 SDK documentation is available in the Acrobat 9.1 SDK download. For offline use, you can download the SDK documentation to your local drive.

Redact to Highlight and Back

| 16 Comments
Share

One of the ways that Adobe Acrobat 9 and X can help you control your work is to make it easier to remove sensitive information before distributing it outside your organization. For those of you not in the legal profession, this is called redaction. Redaction is designed to permanently remove from the document all content that is being redacted and to put an indicator that this happened in it’s place.

The way that redaction works in Acrobat 9 is that you first create redaction marks which doesn’t remove any content and then after you have worked your way through the document completely, you apply those redactions and the information is remove and replaced with, usually black, boxes and optionally codes that indicate the reason the information was removed.

More Fun with the JavaScript API:

If you’ve spent any time in Acrobat SDK land, it shouldn’t come as a surprise that the redaction markup is
just special type of annotation. To demonstrate how easy it is to extend the redaction functionality through JavaScript, I wrote “Joel’s Redaction Utilities”; a simple JavaScript that can be used to toggle redaction markup and highlight annotations. The bulk of the script is actually stolen from my earlier post which iterated through every annotation in the PDF file and…. well…. rather than repeat myself, you can read all about it here.

The beauty of working with the different annotation types in Acrobat JavaScript is that the annotation objects share many of the same common properties. Redaction markup is an annotation of the type “Redact” and highlights are annotations of the type…. you guessed it…. “Highlight”. The one thing you need to know about toggling annotation types is that you actually can’t. The “type” property of an annotation object is read-only. What you need to do (and what’s demonstrated in the example JavaScript) is to collect from the original annotation all of the properties that you are necessary to create a new one of a different type in it’s place. Then you add the new annotation and destroy the original. In the case of this example I get the “quads“, an array of coordinates representing the corner points of a rectangle, and the page number of the original annotation then use those settings as properties for the new one. The new annotation shows up at the exact same coordinates as the original but behaves differently because it’s of a different type. It’s kind of like those transporter accident episodes of Star Trek TOS; all of the properties of the original are basically the same but now Spock has a goatee.

This example demonstrates:

This JavaScript code will add a menu item “Joel’s Redaction Utilities” at the bottom of the “Edit” menu.

Under that menu, you will find two additional menu items.

  • Convert Redaction Marks to HighlightsThis menu item will convert all Redaction Marks to Highlights. The Highlight color will be the same color as your default (usually Yellow).
  • Convert Highlights to Redaction MarksThis menu item will convert all Highlights to Redaction Marks – The Redactions will not be applied by this script though it can be easily modified to do so.

Installing Joel’s Redaction Utilities

1. Quit Acrobat if it is already running

2. Download “Joel’s Redaction Utilities” and then copy the ADBE_JFG_RemoveMatchingAnnots.js file into the following file location:

a. WIN XP

C:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat \9.0\JavaScripts

b. WIN 7 and VISTA

C:\Users\USERNAME\AppData\Roaming\Adobe\Acrobat\9.0\JavaScripts

c. MAC OSX

/Users/YOURUSER/Library/Application Support/Adobe/Acrobat/9.0_x86/ JavaScripts

3. Restart Acrobat

Share

I got an interesting request from Rick Borstein who is one of our Acrobat Product Specialists. It seems that one of his customers is using the new Compare Documents feature in Acrobat 9 for long legal documents. This is actually a perfect use case for this feature but the customer is hampered by the fact that Compare Documents can sometimes find too much. As a text heavy legal document, they don’t have much need for the per pixel differences in graphics and certainly don’t need to see “Matching graphic not found” beside every change bar.

The customer was either looking for a way to “tune” what Acrobat was looking for, which will need to wait for the next release, or simply have an easy way to remove the change indicators that they don’t need. The one tricky part was that they wanted a user interface (UI) to delete all of the change indicators that matched a different set of criteria. I’m not much of a UI designer and even with Windjack’s Acrodialogs plug-in, creating a UI in Acrobat JavaScript would have turned this fun experiment into…. well…. work!

Background:
When Acrobat 9 compares documents, the change indicators that it creates are actually annotations. The Acrobat JavaScript API has been able to manipulate annotations since version 5.0 and that part of the API has evolved quite a bit since then. Because you can ask Acrobat JavaScript to collect the annotations into an array and filter them based on a variety of criteria, it doesn’t require a lot of code to grab all of the annotations in a document and process them; “for” loops can be a lazy programmers best friend.

The Script:
By installing the JavaScript in a folder at the application level, I was able to add a menu item that makes this simple script behave like an Acrobat feature available to any document.

To solve the UI problem, I decided write the script so that it could detect which annotation was selected, determine it’s properties and then look for more just like it. That way the user just needs to select an annotation, choose my menu item "Delete Annotations of the Same Type and with the Same Content as the one Selected" and all that’s it. No UI required.

The links in the bullet list will take you to the appropriate section of the Acrobat JavaScript Reference.

The example demonstrates

This JavaScript will add a menu item “Joel’s Comment Utilities” under “Comments” menu.
Under that menu, you will find three additional menu items.

  • Delete “Matching graphic not found” Annotations
    This menu item will delete all “Highligh” annotations with content “Matching graphic not found”

  • Delete Annotations of the Same Type and with the Same Content as the one Selected
    To use this menu item, select one of the type of comment that occurs frequently that you want to remove all of then select the menu item.
    All comments of the same type and same content will be deleted.

  • Count Annotations of the Same Type and with the Same Content as the one Selected
    Same as above except that comments are not deleted, they are simply counted.

Installing Joel’s Comment Utilities
1. Quit Acrobat if it is already running
2. Download “Joel’s Comment Utilities” and then copy the ADBE_JFG_RemoveMatchingAnnots.js file into the following file location:

a. WIN XP
C:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat \9.0\JavaScripts

b. WIN VISTA
C:\Users\USERNAME\AppData\Roaming\Adobe\Acrobat\9.0\JavaScripts

c. MAC OSX
/Users/YOURUSER/Library/Application Support/Adobe/Acrobat/9.0_x86/ JavaScripts

3. Restart Acrobat

Using the Reduce Comments Script
1. Open a PDF containing comparison comments
2. Choose one of the following commands:

a. Comments | “Joel’s Comment Utilities” | Delete Matching Graphic Not Found Comments
    – or -
b. With another type of comment selected, choose:
Comments | Joel’s Comment Utilities | Delete Annotations with same content as one selected

Share

The Uniform Resource Locator or URL syntax supports multiple resource types in addition to “http:” such as “ftp:”, “tel:” and “mailto:” and PDF forms developers have made use of that fact to make their jobs easier.

Many forms developers create buttons like the ones on the left to mail a document to the next person in a workflow. This button uses the “Sumbit a form” action. The URL that the form gets submitted to starts with “mailto:” which causes Adobe Acrobat or the Adobe Reader to create a mail message with the current document as an attachment.

Most of the time this method works just fine. However, if you need more than one of those buttons on your form, your end user might see a security warning because Acrobat thinks that they are submitting information to more than one web site, a common phishing technique. Fortunately, there is a simple JavaScript that can be used to mail documents without using the “Submit a form” action and causing a security warning.

Full Article

Enforcing Required Fields

| No Comments
Share

Setting a form field to “Required” in the “General Properties” tab forces the user to fill in the selected form field. If the user attempts to submit the form while a required field is blank, an error message appears and the empty required form field is highlighted.

There are some cases where this functionality is not sufficient. You need the user to fill out a particular field before moving on to the rest of the form. You could use JavaScript to dynamically enable or disable parts of the form but that can be cumbersome to keep track of.

The ideal situation would be to, where appropriate, force the user to enter data into a required field before moving to another field. A simple JavaScript can be used to achieve this effect.

Full Article

Share

Many times I find myself turning to JavaScript to perform functions that I end up realizing Acrobat already knows how to do on its own; manipulating date strings is one of those things. JavaScript has a rich set of functions to work with dates such as getMonth(), getFullYear(), and getDay() to return the name of the month, four digit year, and day of the week of any date you pass in.

Full Article

Share

How many forms have you seen that don’t have a date field? Not too many I imagine. JavaScript has a rich set of functions to work with dates but Adobe Acrobat 8 extends those functions even further. With Acrobat, virtually any grammatically correct date expression can be converted into a JavaScript date object that can be used for calculations.

Full Article

Adding Seed Values to Signature Fields

| No Comments
Share

When you digitally sign a PDF, usually you can sign using any supported certificate, from any
certificate authority and state any reason for signing that you like. This is fine in most cases but for
tighter security or to control the document approval workflow, the author of a document might
want to limit the choices a user can make when signing a document. This can be done by applying
“seed values” to a signature field. Seed values are properties that are used when applying your
signature to a signature field. The properties are stored in the signature field and are not altered
when the field is signed, the signature is cleared, or when the form is reset.

Full Article