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

Showing / Hiding Static Pages using javascript (NOT USING LC)

libraboy
Registered: Dec 14 2007
Posts: 94

Hi ALL,

Just wondering if there's any script for showing / hiding pages using javascript? I want to create a form where I can hide two pages and show only if necessary.

Thanks in advanced.

My Product Information:
Acrobat Pro Extended 9.3.1, Windows
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
You need to make template pages out of those and you need the names of the templates. Then you can call:
var sName = "MyTemplateName";var a = this.templates;for (i = 0; i < a.length; i++) {if(a[i].name == sName) {a[i].spawn(this.numPages, false, false);break;}}

That will show that template at the end of the document. This can only be done if the user has a copy of Acrobat Standard or higher or if the document has a Reader Extension.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

libraboy
Registered: Dec 14 2007
Posts: 94
Hi Jim,

How to create template? Do you have any video or sample maybe? Thank you for your quick reply.

Please advice again..

Thank you
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
I can't find anyplace in 8 or 9 to create the templates, but you can do it with Javascript in the debug console:
var t = createTemplate("TemplateName", 1);t.hidden = true;

That code creates a template from page 2 of your PDF (0-based index for pages) and calls it TemplateName, then hides it.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

libraboy
Registered: Dec 14 2007
Posts: 94
Hi Jim,

Pardon my innocent about JavaScript... I don't really understand, I guess I just have to wait for some to email me some sample. Thanks so much for your help! Please someone send me sample.

Thanks Again
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
What don't you understand that I could explain? If you don't understand, I don't see how a sample would help you.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

libraboy
Registered: Dec 14 2007
Posts: 94
I guess I need step by step tutorial :( I don't know where to insert all the codes

thanks
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
For the creation of the templates, you probably want to do that in the javascript console before you distribute the PDF. You can open the console by pressing CNTRL+J. You then enter the code for creating the template, select the text of the code, then hit CNTRL+Enter to execute the code.

As far as the showing of the template, you never specified the condition for when you would show it.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

libraboy
Registered: Dec 14 2007
Posts: 94
Hi Jim,

When I execute the script using the console this is what I get

var t = createTemplate("TemplateName", 1);
t.hidden = true;
t is not defined
1:Console:Exec
undefined

same thing with the other script. Any idea why?

Thanks and so sorry to bug you. :(
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Do you have at least 2 pages in your PDF?

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

libraboy
Registered: Dec 14 2007
Posts: 94
I have tried with 1 and 2 pages still getting that error..

thanks
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
If you have 2 or more pages in your PDF, and you are using Acrobat Pro, and you execute the exact code I wrote, it should work. I don't see anything wrong with the code and it works for me. So I don't know where to go from here.

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

AS
Registered: Dec 10 2010
Posts: 2
Hi Jim,

I really need your help. Please give me your email ID where I can contact you. This is very very urgent.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
First, templates only work with Acrobat not Reader. If you have spent the big bucks for LiveCycle ES server, then you can create a PDF with templates that can work with Reader.

If you have Acrobat 8 Pro, create a form. Navigate to the page you want to make a template. Then Edit the form in Acrobat. Under the "Forms" menu option you should now see an option "Page Templates...". Select this option and a pop up window will appear. Enter the name to assign to the template and click the "Add" button. You can show or hide the template by clicking on the "Eye' icon. Click the "Close" button when done.

If you enter code into the JavaScript console. you need to highlight all of the code you want executed. Then use the key combination + Number pad key to execute the code. Or you can move to each line and execute each line separately. The error occured because the first line "var t = createTemplate("TemplateName", 1);" was not executed.Once you get the template pages created, you will need to create a user iterface to show and hide the teplates as needed.

George Kaiser

AS
Registered: Dec 10 2010
Posts: 2
How this will happen with Acrobat pro with javascript. gkaiseril, please give me your email Id where I can contact you. This is very urgent.
adoacr
Registered: May 4 2011
Posts: 41
so, If im reading this right, the template based approach mentioned here would require the end-user to
have the full acrobat right? it wouldnt work with just the reader?
adoacr
Registered: May 4 2011
Posts: 41
what are the other options to hide/show speicific pages say based on javascript events?
seems like a standard-ish requirement to me...
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Unfortunately, there are no other options...
See my post here: http://acrobatusers.com/forum/javascript/spawn-template-pages-reader

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

maxwyss
Registered: Jul 25 2006
Posts: 255
Either, the end user has a "full" version of Acrobat, or you add Extended Rights with the LiveCycle Reader Estensions server.

There is another possibility, if you can make your users live with "virtual pages", where you have your pages placed as icons in Button fields, and have some show/hide logic. This works quite well, simply requires tha user to use buttons to navigate between the pages, as your physical document has one single page. And printing requires an according printing routine.

Hope this can help.

Max Wyss.