Dynamic Stamps and Non-Adobe PDF Programs
Dynamic stamp functions and features severely limited with non-Adobe PDF readers and editors.
I've programmed thousands of dynamic PDF stamps for individuals and organizations around the world. When activated, most dynamic stamps present the user with a popup dialog window for entering information that will be transferred to the stamp. For a long time, non-Adobe PDF writers and viewers (I'll call them NAPs, for "Non-Adobe Programs") did not support a lot of the JavaScript methods and functions supported by Adobe products, especially the app.execDialog method that is used to create these popup windows. Unfortunately, obtaining a list of supported scripts from these NAPs is like pulling teeth.
While they have been getting better at supporting more scripts, including app.execDialog, there are enough differences between Adobe and its competitors that make it difficult, if not impossible, to create properly functioning stamps with the features we're often asked to include, if those stamps will be used with NAPs.
Take the Acrobat Pro/JavaScript eLearning Course Acrobat Like a Pro
Some of the differences are easy to work around, while others will prevent functionality of a long list of features. There are three main differences between Adobe and NAPs which will be outlined in detail:
1) Document security (encryption)
2) Multipage stamp files
3) Interaction with the document being stamped
Document Security (Encryption)
PDF stamp files are PDF documents. At www.pdfautomationstation.com we always encrypt, or password protect, the stamp files we create for clients for the following reasons:
1) To prevent unauthorized access to proprietary code that we have developed.
2) To ensure that any performance issues are on us, and not the result of somebody messing with the code. We back our work 100% so we need to be confident that nobody has messed with the code if we're going to fix issues in cases where a stamp is not functioning the way it should.
A lot of programmers believe that if you encrypt a stamp file it won't work. This is not necessarily true. It all depends on the permissions you list in the encryption. If you prevent changing the document, document assembly, and page extraction, the stamp will function properly. However, as soon as you prevent content copying the stamp ceases to function. That is because the stamp image needs to be copied in order to stamp it on another document. Everything in this paragraph applies to desktop Adobe PDF readers and editors. And everything in this paragraph goes out the window when dealing with most NAPs*. The workaround for NAPs is easy – just don't encrypt the stamp files. For us, there won't be any proprietary code to protect since, as you will see, none of the special features we add will function with NAPs.
*Disclaimer: I am speaking hypothetically here because there are literally hundreds of NAPs out there. While I am only familiar with a small fraction of them, they seem to be the best ones on the market. I'm assuming if the features won't work on these, they probably won't work on any of them. When you read NAPs in the rest of this article, assume it means most NAPs. When we are asked for special dynamic stamp features to be used with NAPs, we must politely decline. Almost everything will work with free Adobe Reader, so that will have to be their workaround if they want the features.
Multipage Stamp Files
A PDF stamp is a template page in a PDF document. The document can contain multiple pages. The template name, followed by an equal sign, followed by the stamp name makes the template page a stamp. Example: #hzlYJhnCbBfxaJlor0a3wB=My Stamp. If you use the Adobe User Interface (UI) to create a stamp it will give the template a cryptic name like the part before the equal sign in the example. The template name must start with # for the stamp to function properly. The PDF document can contain multiple stamps by containing multiple template pages with stamp names. The title of the PDF becomes the stamp category displayed in the stamp menu for all stamps contained in that PDF (category).
Once again, all of this goes out the window when creating functioning stamps for NAPs. With NAPs, PDF stamps can be contained in only one-page files for some reason. The workaround seems obvious enough. Simply create one stamp per PDF file. There are a couple of problems with this. The first is simply process related. The second is actually prohibitive:
1) Creating one-page stamp files with the Adobe UI.
2) Adding a cover page to a stamp file.
Creating One-page Stamp Files with The Adobe UI
When you use the stamp menu from the Adobe UI to create a stamp (Custom Stamps > Create Custom Stamp), it will create a 2-page PDF file in the user stamps folder, assuming there are no other stamps in the same category. If there are already stamps in the same category in the folder, it will add the new stamp as a template page to the existing PDF file (even if the file is encrypted to prevent changing the document) and continue to add template pages as more stamps are created in that category.
When it's the first stamp in the category and the PDF is created, the first page is blank and the second page is a template page, which is the stamp. If this stamp is for a NAP, you would simply delete the first page. However, if you want to continue to create stamps in separate files in the same category you must first remove the PDF from the user stamps folder to avoid subsequent stamps being added to the same file. If you try to remove the file from the user stamps folder without first shutting down Adobe, you will get an error message that the file is in use, and you won't be able to remove it without first closing down Adobe.
When creating multiple stamps in the same category it's a little annoying to have to keep closing and restarting the Adobe program. I thought of letting the stamps get added to the same PDF file and then extracting the pages into separate files later. The problem with this is that when you extract pages, they lose their template status and are no longer stamp files.
You don't need to use the Adobe UI to create stamp files. You just need to know the components of a stamp file and how they work. Here's a video on how to create a PDF stamp file from scratch, without using the Adobe UI.
Adding a Cover Page to a Stamp File
At www.pdfautomationstation.com we have a standard cover page with our branding and instructions on how to install the stamp file. This cover page is added to every stamp file by simply dragging the page into the pages panel of the file and deleting the blank page (if any) created by the Adobe UI. We can't use the cover page if the stamp is for use with a NAP for reasons already described. It's easy enough to send a separate file with the installation instructions instead of including them as a page in the stamp file. However…
We create a lot of stamps that are customizable by the user. For example, our automatic number incrementing shape stamps have five radio button size settings that are contained on the cover page.
This option allows the user to select a default stamp size and save it in the stamp file. We wouldn't be able to have this option without a cover page. It's not really an issue though because both the sizing option and the automatic number incrementation feature require the stamp to interact with the document that is being stamped. NAPs do not support this interaction, as you'll see in the final point, so these stamps will not function with NAPs anyway. We also have other customizable options like colors, transparency, prefix and suffix text for form field values, and others. Unfortunately, these customizable options are out of the question without a cover page.
Option to Modify Popup Edit Fields in Dialog Windows
The popup dialog window of a dynamic stamp often has popup edit fields (similar to dropdown /combo box form fields). The entries in these fields are hard coded. Customers will ask "will we be able to edit the dropdown entries if they change". Popup dialog windows are extremely difficult to code. If the customers knew how, they probably wouldn't be contracting us to create dynamic stamps for them. Causing an unintended error while attempting to modify the script will cause the entire script to malfunction and no dialog will appear. I'll reiterate here why we encrypt our stamp files. We don't want customers attempting to modify our scripts causing us to have to troubleshoot someone else's error.
We also don't want our customers to have to come back to us for every little modification to a popup edit field list. That's why I developed an administrative feature so they can easily modify the list by simply copying a column from an Excel spreadsheet and pasting it into a dialog window before saving the stamp file. This is not possible with a program that does not allow the stamp file to have a cover page. Instead of not possible, I should say, not feasible, because I suppose I could do it on the same page as the stamp with hidden fields. It would be awkward as I would quickly run out of real estate.
Another difference between Adobe and NAPs, that does not have a section in this article, is the fact that Adobe recognizes fields and their contents that have a rectangle (rect) array of [0,0,0,0]. The position of a field with this rect is a speck in the bottom left corner of the page. While you can't actually see it, even in form editing mode, it exists and Adobe will recognize it, while NAPs will not. So, creating the fields programmatically with rects of [0,0,0,0] to free up real estate on the page is really not an option as a NAP workaround.
The way the administrative feature works is this: The popup edit list is stored in a hidden form field. When the stamp is activated, the script creates an array of the entries by splitting the value of the form field by line returns (each entry is on a separate line in a multiline form field). The script then loops through the array and pushes its indices into the popup edit field object.
Why am I telling you this?
A NAP claimed to support popup edit fields in a dialog. It worked when the entries were hard coded. It did not work when the entries were extracted from a form field list in the stamp file. The core JavaScript loop that pushed the entries into the object was not supported.
Interaction With the Document Being Stamped
The script that runs when a dynamic stamp is activated is contained in a custom calculation of any text field in the PDF stamp file. When this is used in the script to call the document object, the document is the PDF stamp file. The document object of the PDF file being stamped can also be called so that the calculation can interact with this document. event.source.souce is used instead of this to call the document being stamped. Once again, the last sentence goes out the window if the stamp will be used with a NAP, as they don't support event.source.source. The following is partial list of features interacting with the document being stamped that can be programmed into a stamp that will be used with Adobe, but not with NAPs.
Cancelling
When the cancel button in the popup dialog is clicked, it cancels the dialog. Usually, the stamp itself is not cancelled and will appear without any of the dialog information. The cancel button can be programmed to also cancel the stamp so it won't appear at all and will not have to be manually deleted by the user. (Trade Secret: It doesn’t actually cancel the stamp. It automatically deletes it after it is placed).
Location
The stamp can be programmed to land in a specific location on the page.
Sizing
The stamp can be programmed to modify its size to be different from the default size of the stamp.
Transparency Setting
The stamp can be programmed to automatically set its opacity (transparency).
Copying
The stamp can be programmed to be automatically copied to other pages when it is applied to a specific page.
Counting
The stamp can be programmed to count all the existing stamps of its type in the document. This how we keep track of the next number in our number incrementing stamps.
Signing Digitally
The stamp can be programmed to automatically add a digital signature field to the document and then automatically activate the field so the user can digitally sign the document.
Barcoding
The stamp can be programmed to add a barcode with information obtained from the document being stamped.
Editing
The stamp can be programmed to edit the content once the stamp has been placed.
Saving and Closing the Document
The stamp can be programmed to save the document to a specific directory, with a specific name, and even close it after it has been saved. Saving "silently" requires a trusted function stored in the application JavaScripts folder and called in the calculation script of the stamp. This is also true for any function that requires a trusted function.
Almost Anything
Almost any type of document manipulation or information gathering that can be programmed with a script can be executed on the document being stamp during the stamping process. Here are a few examples:
Adding form fields
Filling form fields
Extracting data from form fields
Accessing the info object of the document (Author, Creation Date, Modification Date, Custom Meta Data, etc.)
Conclusion
I did not write this article with the intention of creating a commercial for Adobe products. But as you can see, when it comes to dynamic stamps, the functions and features are limitless when the stamp will be used with an Adobe PDF viewer or writer. When it comes to non-Adobe PDF viewers/writers, those functions and features are severely limited.
Nor was it my intention to write a commercial for my or my company's products or services. I fully intend to share some of the how-to's in future posts. If you are not yet subscribed, now would be a good time. Receive the newsletter directly in your inbox and don't miss another post.
If you have any questions about the contents of this article, please drop them in the comments section. If you would like a quote for custom work, please contact me here.
See you next time.