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

using "WillPrint" correctly

itsmikem
Registered: Jul 14 2009
Posts: 44

Hi list...

I have a 30 page document. The first page has some OCG layers, the rest don't. When the user goes to that first page, layer 2 is shown, and a big link button sequentially shows the rest of the layers. But, layer 1 should only be shown upon printing. I can't get this to work for some reason. Here's my code on the document level:

this.setAction({cTrigger: "WillPrint", cScript: onPrint});

function onPrint(){
layersRef[0].state = true;
this.pageNum = 0;
// this should make it go to the first page and just show the first layer, but doesn't work.
}

Any guidance is appreciated...thanks,
- Michael M.

My Product Information:
Acrobat Pro 9.3.1, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The script needs to be a string. So something like this:
var onPrintScript = "layersRef[0].state = true; this.pageNum = 0;" this.setAction({cTrigger: "WillPrint", cScript: onPrintScript});

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

itsmikem
Registered: Jul 14 2009
Posts: 44
Thanks try67. That worked, but seemed to happen after I want it to. It seems the "WillPrint" event executes after the print dialog box occurs. I wanted to set the layer visible before the dialog. I was able to do this by creating a bookmark and writing the appropriate code there, and the last line is this.print(); but I wanted more control if the user selects "file|print." Is that possible?

thanks,
- Michael M.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
It will launch after the moment you click on OK in the print dialog, and before the file is actually sent to the printer.

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

itsmikem
Registered: Jul 14 2009
Posts: 44
That's what I suspected, so my issue is not solved, but explained. To switch layer visibility prior to printing, it must be executed through a bookmark, because if the script runs after you hit the OK button, it's apparently too late to alter layer visibility, because some representation of the document is already in the queue.

Thanks, try67, for your prompt replies.
- Michael M.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I don't think that's the case. It should be that the changes take effect before the file is sent to the queue.

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

itsmikem
Registered: Jul 14 2009
Posts: 44
I didn't expect it would be the case that way either, but that's how it's working for me.

When I put in a simple alert, it alerted after I pressed OK. Choosing "file|print," in the composite area, it shows the wrong layers visible. So clicking OK at that point still sends the wrong layer visibility to the printer, even though my function might run afterwards.

Having the routine run first in a bookmark, with the last line a call to print(), that worked properly.

Fun stuff!
- Michael M.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Did you actully try it, or are you basing this just on what you see in the Print dialog preview?
It makes sense you don't see the changes in the preview, since they haven't occured yet. However, when you press OK, it should work. If not, it's a bug that you should report to Adobe.

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

itsmikem
Registered: Jul 14 2009
Posts: 44
try67 wrote:
Did you actully try it, or are you basing this just on what you see in the Print dialog preview?
Yes, I tested it both ways. True, it may very well be a bug, but I'm hesitant to report it because I'm by no means proficient in Acrobat scripting to know if there might be some workaround. But, it does seem to be inconsistent behavior.

- Michael M.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
In that case you should report it. It doesn't matter whether there's a workaround or not, it should work as advertised. Just describe in the bug report what you did, what happened, and what should have happened. Also provide details about your version of Acrobat and system configuration.

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

itsmikem
Registered: Jul 14 2009
Posts: 44
I will do that. Thanks for all your feedback, try67! I really appreciate it.

- MM