Sample of the Week:
One of the coolest aspects of Adobe Acrobat and Reader is the fact that they will display PDF files that contain features that are in the specification but that Acrobat isn’t even capable of creating on it’s own… that’s how thoroughly the application is developed. As part of my “Beyond Acrobat” series, this article discusses the little known fact that in addition to page content, links, comments, movies, 3D models… basically any of the PDF annotation objects can be assigned to an Optional Content Group, or “Layers”, as they’re called in the Acrobat user interface. Using the Datalogics PDF Java Toolkit, developers can create PDF files that simply cannot be created in Acrobat alone but display perfectly well. This opens up a world of possibilities but let’s look at one in particular.
Almost every week I get a request from a large corporation that has decided to standardize on PDF forms or some other kind of interactive PDF file that requires the use of Adobe Reader rather than one of the less capable PDF viewers available. The IT groups in these corporations want to know how to force a user to open the PDF file in one of the Adobe viewers.
The short answer is… you can’t.
However, you can construct a PDF file that will warn users if they are not using an Adobe viewer and just simply work if they are. You’d want to create some sort of warning text or graphic with a link to download the Adobe Reader but you’d want this to be hidden if the user is already using the right tools. There are a few things to keep in mind though.
- URL links in PDF tend to be well supported in even the worst of the viewers currently available. I’m not sure why that’s the case exactly but I’ll take it. Unfortunately, links can’t be hidden or shown. Even an invisible link over a blank area of the page will still have a hit area. You don’t want someone accidentally launching their browser to the Reader Download page just because their mouse wandered over a link.
We start by reading in the input PDF file and the image we want to use as the warning graphic and turn it into a PDFXObjectForm so we can add it to the page.
Then we create an Optional Content Group. Optional content refers to sub-clauses of content in a PDF document that can be selectively viewed or hidden. Again, in the Acrobat UI, these are called Layers.
With the layer created, we then simply associate the PDFXObjectForm of our graphic with the new layer and then apply it to the page at the coordinates we want it to appear.
Then we add the link using the same location as the graphic also associating it with the new layer (highlighted).
Try opening the resulting file in different PDF viewers, you should have the same experience in all non-Adobe viewers, but the objects associated with the layer will be hidden when Adobe Reader or Acrobat is used.