These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Fun with Watermarks - Dynamic Text

Terrill
Registered: May 4 2007
Posts: 14

I needed a dynamic text display in PDF format. I wanted different data information to appear on one page, and in the same area. I also wanted the data to be formatted. For example, certain words within the body of the text to be bold, or italicized, etc.

I could have used normal PDF form text fields, etc. but I wouldn’t have the formatting control that I desired. I also didn't have the time to learn LiveCycle, so it had to be in Acrobat.

My answer was: Watermarks.

I've uploaded a copy of these instructions and my sample PDF to one of my web sites. [url=http://wont-tell-you-my.name/pdfSamples/]Feel free to download them[/url].

1. Create your formatted documents in Word and print to PDF.
2. Create a blank PDF to display your data.
3. In the blank PDF:
a) Create a Drop-Down Listbox named cboChoice
b) Add the options/values:
1) space / space (as in type a space for both)
2) Company 1 / c1
3) Company 2 / c2
c) Turn-off the spell checking
d) Select the “commit the selected value immediately”
e) On the General tab: Visible but does not print
4. From the menus, chuse Document / Watermark / Add
a) Select File / Browse and select the PDF with your first “Company Information” document.
b) Set the “Scale relative to document” to 100% (or whatever meets your needs)
c) Click OK.

Now, we need to rename the new Watermark Layer. But, the nice programmers at Adobe didn’t give us an easy way to even see that we HAVE this layer. So, borrowing a script from this site that I stole...

5. From the menus, chuse Advanced / Document Processing / Document JavaScripts
a) Type-in the name Init (that’s an Uppercase “I”) and click Add
b) Delete everything inside the script editor, and type the following code:

 // make all watermarks visible in the Layers panel...
this.setOCGOrder(this.getOCGs());

Once you close the script and the dialog, you should be able to open the Layers Navigation Panel and see your watermark.

6. Right-Click on the Watermark and chuse Properties, and set the following:

a) Name: c1
b) Default State: off
c) Visibility: Visible when on
d) Print: prints when visible
e) Exports: never exports
f) Click OK
7. Save your work. Name the file ResumeExample.pdf

Note: Yes, you can still see the watermark. Click the Eye in the navigation panel.

8. Now, repeat the process from steps 4 through 7 to add your second watermark (which you will name “c2”), with one small exception: in step 5, simply open the Document JavaScripts, and close the dialog. This will make the second watermark visible in the Layers Navigation Pane.
9. Turn-off the Eye in the navigation pane to hide the watermark.
10. Open the Document JavaScripts, and create a new function named WaterMarkShow, and add the following code:

 function WaterMarkShow(sWmName)
{
    var aOCGs = this.getOCGs();
 
    // app.alert("Number of Watermarks == " + aOCGs.length);
 
    for(var i=0; aOCGs && i<aOCGs.length;i++)
    {
        // app.alert("Name = " + aOCGs[i].name);
        aOCGs[i].state = aOCGs[i].name == sWmName ? true : false;
    }
 
}

9. Right-click on the cboChoice combobox, and chuse Properties
a) On the Calculate tab, select Custom calculation script, and edit
b) Place the following code in the script:
WaterMarkShow(this.getField("cboChoice ").value);
Selecting Company 1 or Company 2 in the drop-down list switches to the appropriate watermark. Selecting the blank entry turns-off all watermarks.

If nothing else, it’s an interesting exercise in turning on/off layers, and you might find it useful. Keep it with your "sample code," eh?

Enjoy!

-- Terrill --
"42"

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
It should be noted that the above code will only work with version 6 or above of Acrobat Standard or Professional. The version restriction is due to the fact that version 6 is the first version to suuport the "OCG" object and the restriction to the Standard and Professional version is because the "name" property of the "OCG" object is not available to the Reader and Approval products.

George Kaiser

casimirvovo
Registered: Dec 28 2007
Posts: 1
Hi !

Does anyone know how to access ocg object members from c# ?

What i could do is get an array of objects (array of layers) from the PDDoc's JSOBject by calling
the gettype().InvokeMember's method with parameter "getOCGs", but i did not succeed to get or set the state, name,... for any ocg belonging to that array.

I have a pdf document which is the result of merging several docs.
I need to programmatically group layers by name in that document, so layers of one type only appear once in the layers tab.

Thanks !