Document Action will close

Dec 11, 2017

Copy link to clipboard

Copied

Hi ,

I'm trying to ask the user to change his mind if he didn't really want to exit from the (Opened PDF Doc),, so i go to Document Action at (Document will close) and write the following :

var cMsg = "Are you sure you want to close ?";

cMsg += "\n\n";

cMsg += "Contiunue ? \n\n ";

var nRtn = app.alert(cMsg,2,2,"Warning ! ");

if(nRtn == 4)

{// A yes Response

  // Code for doing the thing you do on a yes

  this.closeDoc();

}

else if(nRtn == 3)

{ // No Response

  //event.value = 0; // assume do nothing

  beep

  !this.closeDoc();

}

else  

{ //Unknown Response

  beep

  !this.closeDoc();

}

But the Above Code is Closing the Document even if the user hit yes or no? ho do i change it to not close the document if the user hit (No)... thanks for any tip

The script can't abort the file close command. The only way is if the user closes the file using a button you added to it, which executes this code. But if they click the X button or File - Close or Quit, the file will close, no matter what.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

463

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Document Action will close

Dec 11, 2017

Copy link to clipboard

Copied

Hi ,

I'm trying to ask the user to change his mind if he didn't really want to exit from the (Opened PDF Doc),, so i go to Document Action at (Document will close) and write the following :

var cMsg = "Are you sure you want to close ?";

cMsg += "\n\n";

cMsg += "Contiunue ? \n\n ";

var nRtn = app.alert(cMsg,2,2,"Warning ! ");

if(nRtn == 4)

{// A yes Response

  // Code for doing the thing you do on a yes

  this.closeDoc();

}

else if(nRtn == 3)

{ // No Response

  //event.value = 0; // assume do nothing

  beep

  !this.closeDoc();

}

else  

{ //Unknown Response

  beep

  !this.closeDoc();

}

But the Above Code is Closing the Document even if the user hit yes or no? ho do i change it to not close the document if the user hit (No)... thanks for any tip

The script can't abort the file close command. The only way is if the user closes the file using a button you added to it, which executes this code. But if they click the X button or File - Close or Quit, the file will close, no matter what.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

464

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

The script can't abort the file close command. The only way is if the user closes the file using a button you added to it, which executes this code. But if they click the X button or File - Close or Quit, the file will close, no matter what.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 1
Dec 11, 2017

Copy link to clipboard

Copied

Thank  you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

Info: !this.closeDoc(); will also close the document.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

Very inventive but very wrong too! In fact it tries to close it twice (once because it’s going to close anyway and once be you call this.closeDoc.) This could even cause a crash.

! something does not mean “don’t do something” it means “do something and invert the result”.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

it work good in a button with no crash, what do you suggest instead using !this.closeDoc()

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

“do something and invert the result”. only if you use logic operators in comparing values between two arguments

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

This is not correct. Where did you read this?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

i didn't, it some times happened to me when trying crazy things in Acro JS!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

Can you share a sample file?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

All "!" does is take a Boolean value and return it after applying the NOT logical operator on it. It does not execute (or not execute) anything by itself. You give it a value of TRUE and it will return FALSE. You give it FALSE, it will return TRUE. That's it.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 1
Dec 11, 2017

Copy link to clipboard

Copied

no it doesn't if you use it in a button

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

Remove the beep lines and you will see what happens.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

not happened also after removing the Beep lines, I'm using Adobe Acrobat Pro DC

Version 2018.009.20044 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

What code do you use now?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

var cMsg = "Are you sure you want to close ?"; 

cMsg += "\n\n"; 

cMsg += "Contiunue ? \n\n "; 

 

var nRtn = app.alert(cMsg,2,2,"Warning ! "); 

if(nRtn == 4) 

{// A yes Response 

  // Code for doing the thing you do on a yes 

  this.closeDoc(); 

else if(nRtn == 3) 

{ // No Response 

  //event.value = 0; // assume do nothing 

  !this.closeDoc(); 

 

else    

{ //Unknown Response 

  !this.closeDoc(); 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

medos20  wrote

var cMsg = "Are you sure you want to close ?";   cMsg += "\n\n";   cMsg += "Contiunue ? \n\n ";      var nRtn = app.alert(cMsg,2,2,"Warning ! ");   if(nRtn == 4)   {// A yes Response     // Code for doing the thing you do on a yes     this.closeDoc();   }   else if(nRtn == 3)   { // No Response     //event.value = 0; // assume do nothing     !this.closeDoc();      }   else      { //Unknown Response     !this.closeDoc();   }  

This code will always close the document.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

OK, but what about other option available ? i mean how to do it the right way ?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

medos20  wrote

OK, but what about other option available ? i mean how to do it the right way ?

To not close the file? Simply do nothing. Assuming the code is executed from a button it will just return to the file as normal.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 1
Dec 11, 2017

Copy link to clipboard

Copied

The Correct Code will be :

var cMsg = "Are you sure you want to close ?"; 

cMsg += "\n\n"; 

cMsg += "Contiunue ? \n\n "; 

var nRtn = app.alert(cMsg,2,2,"Warning ! "); 

if(nRtn == 4)

{// A yes Response

  // Code for doing the thing you do on a yes

  this.closeDoc();

}

else if(nRtn == 3)

{ // No Response

  event.value = 0; // assume do nothing

}

else  

{ //Unknown Response

  event.value = 0; // assume do nothing

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

Lines 10-17 can be removed. A button doesn't have a value, so they don't do anything, anyway.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 2
Dec 11, 2017

Copy link to clipboard

Copied

The Doc/WillClose event is triggered before a document is closed. However, it does not listen to the rc return code.

You won't be able to stop the document from closing.

J-

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 1
Dec 11, 2017

Copy link to clipboard

Copied

The clue is in the action name. It's called "Will close" not "Might close" or "Your chance to not close". Most actions with "Will" in the name are already committed.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

“do something and invert the result”. only if you use logic operators in comparing values between two arguments

No, you are wrong. It inverts the result and (since it is not tested) throws it away. Where on earth did you get the idea that you can use this to cancel anything at all, still less a call already under way?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

That seems valid but  NOT valid when run as a document-will-close action where it will not stop the document closing and might cause a crash.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0
Dec 11, 2017

Copy link to clipboard

Copied

Yes, the final code is for button only

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 11, 2017 0