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

Hiding PDF Content Dynamically

Lakario
Registered: Jun 10 2009
Posts: 6

I have a PDF document with a single paragraph blurb in it that needs to be excluded or included depending on the context. After spending some time looking around I couldn't find any way to set a static text block to hidden. That being so, I considered possibly having the context exist as a textfield that I simply set or unset when the document is filled in by my ASP.NET application. This option would work, but it cause me to lose the formatting of the text as it now (which isn't something I want to do).

Is there any graceful way to turn a block of text on or off dynamically? If not, are there any hacks that would produce a similar result?

Thanks!

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes there is. First, you can maintain formatting in a text field, or annotation like the "Text Box" tool, by setting it to use Rich Text.

But you can also group the text into an OCG layer which can be turned on and off with JavaScript. There are a couple of 3rd party tools for adding OCGs to a PDF, like a Aerialist from www.artspdf.com ( I think Callas has one too). But you can also do this by putting the optional text in a separate PDF and then overlayng that PDF onto your main document by adding it as a watermark. Here is an article on createing and using OCGs in Acrobat JavaScript.

http://www.acrobatusers.com/tutorials/2006/create_use_layers

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lakario
Registered: Jun 10 2009
Posts: 6
thomp wrote:
Yes there is. First, you can maintain formatting in a text field, or annotation like the "Text Box" tool, by setting it to use Rich Text.But you can also group the text into an OCG layer which can be turned on and off with JavaScript. There are a couple of 3rd party tools for adding OCGs to a PDF, like a Aerialist from www.artspdf.com ( I think Callas has one too). But you can also do this by putting the optional text in a separate PDF and then overlayng that PDF onto your main document by adding it as a watermark. Here is an article on createing and using OCGs in Acrobat JavaScript.

http://www.acrobatusers.com/tutorials/2006/create_use_layers

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]
Thank you very much for the detailed response. I attempted using the Rich Text Format of the textbox but it did a poor job of preserving the layout I wanted unfortunately. As for the JavaScript and layers approach this would be perfect were it not for the fact that the field needs to be toggled at creation time (the PDF is a template that gets filled in) and I can't invoke JavaScript outside of the context of the PDF itself nor do I have any way to let the PDF know at build time that I would need to toggle a layer using JavaScript.

The solution I came up with is a complete hack... but it suits my purposes fairly well:

1) Place a readonly, hidden textbox over the area I will be "hiding" that is the same dimensions as that region
2) Using my PDF manipulation library in C# find the text field object
3) Import a 1x1 image file with a background that matches the document and stretch it over the rectangle defined by my textbox using PDF library

The above steps will visually hide the text from the viewer, but it is still selectable should they drag their mouse over the image area. The finally format of this PDF is, in all cases, print so the fact that the user can select the text in a PDF viewer is non-pertinent as the printed version will simply show nothing.

Not great, but it works...