Print Page | Close Window

Ruling out non-adobe viewers

Printed From: Foxit's Planet PDF Forum
Category: Lets Talk PDF
Forum Name: JavaScript
Forum Description: Discussions relating to the use of JavaScript within PDF.
URL: http://forums.planetpdf.com/forum_posts.asp?TID=861
Printed Date: 07 Dec 2019 at 7:41am
Software Version: Web Wiz Forums 11.10 - http://www.webwizforums.com


Topic: Ruling out non-adobe viewers
Posted By: zhirik
Subject: Ruling out non-adobe viewers
Date Posted: 17 Jun 2013 at 5:29pm
Hi guys,
 
I'd like to add a doc-level script (thru another script) that will check the viewer type, and if it neither Acrobat nor Reader, the document will close.
 
So I wrote:
 
...
this.addScript("CheckViewer", "var viewer = app.viewerType;\
     if(viewer !== \"Exchange-Pro\") && (viewer !==\"Reader\")\
     {app.alert(\"This Document Requires Adobe Reader or Acrobat Version 10 or Later.\");\
    this.closeDoc(true);}");
 
The script is correctly placed in the document, but the console notifies on syntax error on the line that comes after the script! But this line does not exist!
 
I also tried:
this.addScript("CheckViewer", "if(app.viewerType !== \"Exchange-Pro\") && (app.viewerType !==\"Reader\")\
     {app.alert(\"This Document Requires Adobe Reader or Acrobat Version 10 or Later.\");\
    this.closeDoc(true);}");
 
I guess, there is something wrong with  if(viewer !== \"Exchange-Pro\") && (viewer !==\"Reader\") part, but I can't figure out what the problem is.
 
I would appreciate your advice! Confused



Replies:
Posted By: gkaiseril
Date Posted: 17 Jun 2013 at 6:24pm

You also need to check for viewer "Exchange" and the viewer version.

if(viewer !== \"Exchange-Pro\") && (viewer !==\"Reader\")
 
 if(viewer !== \"Exchange-Pro\") && (viewer !==\"Reader\")
 
Should have both logical statements within parenthesis.
 
 if ( (viewer != \"Exchange-Pro\") && (viewer !=\"Reader\")  )
 
I would also use the "!=", not equal, and not the "!==", strict not equal, comparison.
 


Posted By: zhirik
Date Posted: 17 Jun 2013 at 9:19pm
Hi gkaiseril,

Thank you for your response and for the suggestions!

Could you please explain why it is better to use the "!=", not equal, and not the "!==", strict not equal?

Thank you in advance!

Originally posted by gkaiseril gkaiseril wrote:

You also need to check for viewer "Exchange" and the viewer version.

if(viewer !== \"Exchange-Pro\") && (viewer !==\"Reader\")
 
 if(viewer !== \"Exchange-Pro\") && (viewer !==\"Reader\")
 
Should have both logical statements within parenthesis.
 
 if ( (viewer != \"Exchange-Pro\") && (viewer !=\"Reader\")  )
 
I would also use the "!=", not equal, and not the "!==", strict not equal, comparison.
 


Posted By: aandi
Date Posted: 17 Jun 2013 at 11:34pm
Remember that non-Adobe viewers might have no JavaScript, or might return Exchange-Pro or Reader themselves; and that Adobe readers might have JavaScript off.


Posted By: zhirik
Date Posted: 18 Jun 2013 at 9:57am
Hi aandi,
 
You are right. Foxit, for example, completely ignores this script, even with Javascript enabled. And even of I set the app.viewerVersion to <10 (with Foxit 6 installed), the file is opened without any problem. Too bad..
 
Originally posted by aandi aandi wrote:

Remember that non-Adobe viewers might have no JavaScript, or might return Exchange-Pro or Reader themselves; and that Adobe readers might have JavaScript off.


Posted By: zhirik
Date Posted: 18 Jun 2013 at 10:05am
A small update: Foxit disguises itself as "Reader". The question is if it's possible to detect it as "Foxit" in any other way?
 
Thank you for your response in advance!
 
Originally posted by zhirik zhirik wrote:

Hi aandi,
 
You are right. Foxit, for example, completely ignores this script, even with Javascript enabled. And even of I set the app.viewerVersion to <10 (with Foxit 6 installed), the file is opened without any problem. Too bad..
 
Originally posted by aandi aandi wrote:

Remember that non-Adobe viewers might have no JavaScript, or might return Exchange-Pro or Reader themselves; and that Adobe readers might have JavaScript off.


Posted By: aandi
Date Posted: 18 Jun 2013 at 11:08am
By experiment, you could find something it doesn't do (and preferably isn't likely to do); try it; and deal with the exception. 


Posted By: zhirik
Date Posted: 18 Jun 2013 at 12:50pm
Hi aandi,
 
You are right - it seems to be the only way to do it. But it seems that Foxit can do everything that Reader does and even do it better. ;-)
 
Have a nice day!!!
 
Originally posted by aandi aandi wrote:

By experiment, you could find something it doesn't do (and preferably isn't likely to do); try it; and deal with the exception. 


Posted By: Rowan
Date Posted: 19 Jun 2013 at 12:50am
I daresay that Foxit pretends to be Adobe Reader in order to get around PDF files (produced by Adobe products) that contain JavaScript which prevents them from opening in anything but the latest version of Adobe Reader.

By the way, I'll say the same thing to you as I've said to Adobe, this is a bad idea and it breaks the Portable Document Format.


Posted By: gkaiseril
Date Posted: 19 Jun 2013 at 5:08pm

ISO committee could add a metadata field like "ViewerVendor" property to the app object so one could tell whose product is being used, but this would only work for those programs/apps that add this item and not apply to older versions of programs/apps. It would take years for this to become a usable standard. And it could still be omitted and not be in non-conformity with the standard.

It might more helpful to know if the viewer is being used on a mobile device. But this is limited since not all mobile devices have or simulate JavaScript. 


Posted By: aandi
Date Posted: 20 Jun 2013 at 12:19am
And, crucially, vendors could still lie about being some other piece of software if it suited them for any reason. It's very likely some would.


Posted By: zhirik
Date Posted: 20 Jun 2013 at 5:32am
Hi aandi,

That's why I said that nobody would dare to use the word "Adobe" in their identifiers. They may be sued for that.

But everybody is afraid of breaking old scripts. So let's stay with IPv4 and never move to IPv6 just because it may temporarily break something.Confused


Posted By: budatlitho
Date Posted: 01 Oct 2013 at 2:44pm
I'm placing as page 1 a page with a warning that it is not being viewed with a reader that has Javascript. I then place in the Page Properties>open a script to set focus on the first field on page 2. If no Javascript, page 1 is shown. If Javascript is available, page 1 briefly displays and then page 2 is shown.
Not the most elegant solution, but it does work.


Posted By: aandi
Date Posted: 01 Oct 2013 at 3:27pm
They may not thank you for the extra sheet of paper if it is printed, but it may be good for a form that is never printed. Thanks for sharing the tip.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.10 - http://www.webwizforums.com
Copyright ©2001-2017 Web Wiz Ltd. - https://www.webwiz.net