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

How do I remove all basic document level javascript code from a PDF?

Acrobatica
Registered: Jul 24 2009
Posts: 15

Hello everyone,
I have a couple of questions for you regarding abasic document level script.

We have a document which displays an alert message on every single page open which is very annoying. When scrolling throgh a document to find something the screen is flooded with these alert messages.

The Document Java Script is called VARS and has the single entry:
var accepted =1; <-- I have already set this to 0 to disable these messages, but I would like to remove the scripts as they are redundant.

I tried deleteing the Document Javascript VARS and the scripts below but I not sure what XML tags I need preserve for this to work. Can anyone show me what tags I need to keep please?

Editing all Javascripts looks like this :

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------
 
//<ACRO_Document-Level>
//<ACRO_source>VARS</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Document-Level.VARS ***********/
var accepted = 0;
//</ACRO_script>
//</ACRO_Document-Level>
 
//<ACRO_Page-Actions>
//<ACRO_source>ACRO_Page1.Page Open</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Page-Actions.ACRO_Page1.Page Open ***********/
if( accepted == 1 )
{
app.alert(
"This message is soley designed to irrate and annoy.\r"+
"Please click okay to continue.\r"
,1,0);
accepted = 1;
}
 
//</ACRO_script>
//</ACRO_Page-Actions>
 
//<ACRO_Page-Actions>
//<ACRO_source>ACRO_Page2.Page Open</ACRO_source>
//<ACRO_script>
/*********** belongs to: ACRO_Page-Actions.ACRO_Page2.Page Open ***********/
if( accepted == 1 )
{
app.alert(
"This message is soley designed to irrate and annoy.\r"+
"Please click okay to continue.\r"
,1,0);
accepted = 1;
}
 
//</ACRO_script>
//</ACRO_Page-Actions>
.
.
.

The other question I have is what external editor tool do I use to edit all Javascripts which cannot be display the scripts in full in the Edit Dialog. I am using an old copy of Adobe Acrobat 5.0 (Standard I think) to try and fix this.

Thankyou,
Robert.

My Product Information:
Acrobat Standard 5.x or older, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
What other scripts exist for doucment actions (open, close, will save, did save, will print, did print, page open, page close), calculations, mouse actions. links, bookmarks?

I would use JavaScirpt to loop through the page of the PDF and use the 'setPageAcrtion()' method to null out the 'open' page action for each page.

// loop through the pages of this pdffor(i = 0; i < this.numPages; i++) {this.setPageAction({nPage: i, cTrigger: "Open", cScript: "");} // end loop through pages

You can use any text editor. This means text not a document editor like Word. Note Pad, Text Pad, Ultra Edit, Note Pad++.

George Kaiser

Acrobatica
Registered: Jul 24 2009
Posts: 15
Hi,
Thankyou for your reply. there are no other scripts assigned to any document actions.

There must be a way to remove all the Javascript rather than writing additonal code to disable the document open action?

I tried opening the document into Notepad and searched for the string "Please click okay to continue".
It was only able to find one instance and the Javascript isn't particularly easy to read either.

Acrobats JavaScript Editor shows multiple entries as above and is formatted correctly.
How do I achieve the same result with any of the above text editors?
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
The script provided will remove only the 'pageOpen' actions. You could even create a "Batch Process" using this script so you could apply this to any number of PDF's.

You only have to run this code once from the JavaScript console and save the PDF to have a copy of the PDF without the page open script. You could even cut the code from here, open the JavaScript console, past the script into the window, and execute it. No special editor needed.

George Kaiser

Acrobatica
Registered: Jul 24 2009
Posts: 15
I follow you now. I tried copying and pasting you code into the console but I get an undefined error when I press enter on the numpad.
An undefined error is not terribly informative. Any idea what could be wrong?

As below:
for(i = 0; i < this.numPages; i++){this.setPageAction({nPage: i,cTrigger:"Open", cScript: ""); ) undefined
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
There was an error in the code posted.
for(i = 0; i < this.numPages; i++) {this.setPageAction({nPage: i, cTrigger: "Open", cScript: ""} );}

The code will end with 'undefined' because there is no value created by the script.

To execute the code, one needs to highlight the code, then hold down the key and press the keypad's key.After the script runs, save and close the PDF, and then reopen the PDF and make sure the action has been removed.

George Kaiser

Acrobatica
Registered: Jul 24 2009
Posts: 15
Thanks George, I tried doing as you suggest and I now see the following error:

TypeError: this.setPageAction is not a function
undefined

Could it be that this funtion isn't supported in Acrobat 5.0? Maybe there is an alternative?

By chance, when looking for a solution I just found that the PDF Consultant tool has the option to Detect and Remove Javascript actions. I tried this and it worked however the VARS script still remains. I can delete the VARS Javascript with the Document JavaScripts tool but the VARS name still remains.

I thought I would mention this in case this it provides a possibility of a slightly different solution path if there is no alternative to the setPageAction function. Maybe you could suggest a way to do this by JS or other means?

EDIT: My mistake, I can remove the VARS name too. The only noticeable side effect of doing this is that Acrobat will still load a the JavaScript Editor even though it only contains this:

//-------------------------------------------------------------//-----------------Do not edit the XML tags--------------------//-------------------------------------------------------------

Now If I could get it to behave like a PDF that has no JS and therefore not open the JS Editor then I would be absolutely delighted. Well, what do you know, that is how all PDFs behave when the JS Editor is selected.:)