Back to Basics: Using Acrobat Stamps with the Datalogics PDF Java Toolkit

Back to Basics: Using Acrobat Stamps with the Datalogics PDF Java Toolkit

Sample of the Week:

As “Back To Basics” month comes to a close, we’re going to visit the Acrobat stamp functionality again. This time I’ll walk you through the process of using the Datalogics PDF Java Toolkit to stamp a PDF file using the built in Stamps that are installed with Adobe Acrobat and Reader.

The Comment panel in Adobe Acrobat, and recently, Reader, allow you to add a number of stamps to any PDF file. These stamps are designed to look similar to the old time rubber stamps that you’d apply to a paper document. Acrobat will allow you to create your own custom stamps and if you know a little JavaScript, you can even create dynamic stamps that can gather information from the user before being applied to the document.

StampPaletteUnder the hood, stamps are just special pages in a set of special PDF files that can be located in either the Acrobat application folder or in the user’s Acrobat preferences folder. As long as the PDF file with the stamps in it is configured the right way, Acrobat can build a user interface and allow end users easy access to the stamps right from within the Acrobat Stamps Palette or from the stamp icon drop-down menu.

pageTemplatesStamp files must contain two important parts for Acrobat to recognize them and display their stamps. They need to have a Title in the document metadata; this will present itself in the Acrobat UI as the group under which the stamps will be displayed in the Stamps palette. Then each page that you want to use as a stamp must be identified as a page template. Template Pages are a kind of named page and can either be visible or invisible. In the case of stamps, they need to be visible and must conform to a specific naming convention. The template name starts with a unique identifier, followed by an equal sign, followed by a label. The label is what shows in the Acrobat user interface when you display the stamp names.

Now, as a developer trying to automate the placement of stamps, we don’t need to generate a user interface but we can use the stamp file format to locate the stamp that we want to apply regardless of the actual page number that it has in the file. Using Datalogics PDF Java Toolkit we can use the template names to locate stamps and add them to a PDF page in the same way that Acrobat does.

After reading in the two input files, we simple need to locate the PDFPage with the page template name that corresponds to the stamp that we want to add to our destination PDF page; in this case the “Confidential” stamp. The Confidential stamp template name is “SBConfidential=Confidential” and the PMMTemplates service makes it very easy to use this name to get the page we want.

If the template name isn’t found, the method returns null but if it is, you get the page you want regardless of it’s location in the PDF file.

After you have a handle to the page you want to use as the stamp, it’s just a simple matter of creating a PDFAnnotationStamp and then assigning that page as the “Normal” appearance. We can also optionally add some metadata to the stamp that will appear in the Acrobat user interface in the Comments panel.

Now all that’s left to do is position the PDFAnnotationStamp and add it to the page.

Using this method, developers can also add custom stamps to their PDF files. Using the Datalogics PDF Java Toolkit, developers can achieve complete interoperability between their server processes and the desktop versions of Adobe Acrobat and Reader; even with custom stamps.

Leave a Reply

Your email address will not be published. Required fields are marked *