1

I have a pdf which needs a javascript prompt that would asks for a username and password or just one of these. I have tried the native javascript way inside the javascript editor of acrobat. Alerts work fine but prompts are not working for me.

var customerName = prompt("Please enter your name", "");

have also tried

var customerName = app.prompt("Please enter your name", "");

EDIT: WEll i tried to remove the complex parts of the process so that you guys can understand better. but i guess i owe you guys some explanation on what i am trying to achieve.

Well i have an empty pdf which i am going to send to my users and when it is opened it will ask for a username/password which is then submitted to my website through an api. I already have an api in place which would check for the correct credentials and on success would print the desired pdf content on a php page, which could be grabbed as a curl request through the javascript inside the empty pdf. And when i want to revoke the access to the user i would just delete the user from the database on my server. So the next time he wants to read the pdf he wont be able to pass through the api security.

Well i know there are some drawbacks on applying so many restrictions like pdf reader compatibility etc. but even if it only works on acrobat that would be fine. Later on will try to remove the print and save options etc.

Most of the parts are done the only thing i am stuck at the moment is on how to send a form GET request to a url. I think js prompt doesn't work in acrobat so i guess i have to send the data through an acrobat form. Any one knows how can i send a get request through the forms or get the values of input boxes in javascript?

omer Farooq
  • 3,146
  • 4
  • 21
  • 52
  • 2
    "the native javascript way" — There isn't a native JavaScript way, the `prompt` method of an API supplied by web browsers, it isn't defined in the JavaScript specification. – Quentin Jul 27 '15 at 13:18
  • So in short you want to make some sort of password verification before the user can download or view the file? – TrojanMorse Jul 27 '15 at 13:20
  • 2
    There is no such thing as a prompt method in the [Adobe Javascript API](http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_api_reference.pdf) – yms Jul 27 '15 at 13:24
  • If your intent is to authorize the user for viewing the document, doing that *from within the document* probably isn't the best idea. Essentially it would mean that you first provide the file to the user, and *then* you check if the user is authorized to receive the file. That's generally best done in the opposite order. – David Jul 27 '15 at 13:29
  • 1
    @david On top of that, most of the PDF viewers out there (other than Acrobat Reader) do not support running javascript actions anyway, and even with acrobat reader, it can be disabled – yms Jul 27 '15 at 13:34
  • Kindly checkout my edit for further information – omer Farooq Jul 27 '15 at 14:07
  • Just FWIW, in Acrobat Javascript, this would be app.response() . – Max Wyss Jul 27 '15 at 20:14

1 Answers1

1

Thank you everyone, i just found out on how to post data to a webpage. Here is the link, Can a PDF fillable form post itself to an HTTPS URL?

Instead of choosing "PDF the complete document" from the format options, choose html.

Community
  • 1
  • 1
omer Farooq
  • 3,146
  • 4
  • 21
  • 52