So, the title of my thread is very straight forward and that's what I am after... a piece of JS code that ensures me that the document IS in Reader.
The reason is because I have a set of PDF documents stuffed with a lot of JS and that just get stuck when the user's browser opens it in a tab instead to download it.
I kind of worked it around by adding the HTML5 property 'download' at my links declaration to force the download, however I know that not all browser versions recognizes it so once in a while I still will have someone staring to a broken document into a browser tab.
I would appreciate immensely if someone could tell me if it does exist such JS code that may help me with this detection.
The way to do it is to display an error message by default, and then hide it when the script detects that the file is opened in Adobe software. That way, even if JS is not supported at all, the error message will still show up when the file is opened.
Yup MVP this was exactly what I did after to stop and think a little while. Thank you anyway, I marked you answer as the right one!
how would I do that?
Are there any instructions? Because I do know how to add a javaScrip, but how would I add an error message by default? and then make the script make it dissapear?
Does anyone here know how I get the systen creation date of the file? what I am doing right now (this.info.CreationDate;) gets the creation date under Adobe-Properties and that seems to be a different date....
I already got the solution, thanks!
PS: Actually I didn't need any JS piece of code!
can you share it? I am having the same problem....
I think I got it!
the problem now is, that when I have the document open (in adobe) the form field disappears because my code runs because it is obiously open in adobe. Then when I upload the document on a sharepoint and open it in the browser it still is not visible because I think the code ran and made it dissappear when I had it open in adobe.
I need to make the field visible again and then save, not open and upload to sharepoint.
This is rather tedious but I guess there is no way around it?
There is a little while since I did that so I can't recall exactly how to perform each step but the overall idea is quite simple. First you will need Adobe Acrobat Pro to edit your PDF document. I believe you already have it though since you mentioned that you know how to add JS to a PDF document. Said that let's go...
1) Open your PDF document with Adobe Acrobat Pro
2) Make layers
3) Add a new layer and name it "error"
4) Place into this layer an image or a text with your custom error message such as "You cannot view this document in browser. Please download it and open with Adobe Reader!"
5) Ensure that ALL layers are invisible and only this one is visible (only its checkbox should be checked and all others remain unchecked)
7) Into the window paste the following code:
var layers = this.getOCGs();
var aLayers= ["contents","error"];
if (layers[i].name == "error")
layers[i].state = false;
layers[i].state = true;
It should do the magic for you.
The trick here is that every time this document is opened (be in browser or in Adobe Reader) there WILL BE the message error. However when it be opened in Reader it will run the code that makes it invisible instanly so the user never will see it. By the other hand when it be opened in a browser tab, since browsers has not the ability to run PDF internal JS the message error will simply stay visible. Simple.
"... since browsers has not the ability to run PDF internal JS the message error will simply stay visible."
This is not correct!
Really? Sure! LoL.
E.g. Internet Explorer with Acrobat Reader add-on.
actually, just solved that, I added a script when the file is saved to set the form field to appear again 🙂