Fill PDF form with javascript - javascript

This is what I have:
User fills very long html form
User gets link to download different pdfs (this are fillable forms), links are generated using javascript
User clicks link, url is generated (with the data the user submitted before), data is processed in the form and fields are completed *this is done using javascript inside the form).
User get pdf back with fields completed.
The problem I'm running is that in some cases the data needed to send to the form is around 8000 characters, when IE only allows 2083 character in the url.
As requested by client, we need to do everything client side, that means no access to php, c#, java. Also I'm using Acrobat Pro X, to work with the pdfs.
Is there a way to submit a post request, process that request in the pdf, fill the form and return the filled form to the user? Is there another way to go around the 2083 character limit of IE?

Why do you need to send 8000 characters of data to the server if you want to fill out the form on the client side? Seems like all you need to do is to establish communication between the JavaScript in the HTML page and the JavaScript in the PDF. This is explained here: PDF hostContainer callback
PS: I'm the author of the book from which this excerpt was taken: http://www.javabeat.net/2011/04/javascript-communication-between-html-and-pdf-in-itext/

Related

How to apply password prompt javascript on acrobat pdf

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?
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.

Return data from SQL based on user input without reloading form - Classic ASP

I am working on adding a new feature to an existing Classic ASP application. In this feature the user will scan a bar-code which will input its value into a text field in a form within a bootstrap modal. The scanner is configured to send a TAB as well after the data.
What I need is a way to query the database on field exit and populate other fields in the modal with data from the query that is based on the scanned value. I need to do this without reloading the page or closing the modal so the user can verify this information and make changes before saving the form.
What is the best way to do this? I have no issue writing the SP, but do not have any idea how to call it and then return it's values. Can I possibly use JavaScript/PHP for this?
You will need to use some ajax
https://learn.jquery.com/ajax/
Basically you would send a request to your .asp script which will run the stored procedure then send a response using Response.Write.
Then parse that response in jquery.
Unlike ASP Classic, AJAX is a new technology so it works better with JSON.
There aren't many JSON libraries
You can use json2.asp:
https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp
Or if you want you can try it XML, but its unpopular these days and more tedious to parse.
You mentionned PHP, that's not a bad idea because, it's all built in for you see:
http://php.net/manual/en/function.json-encode.php
Hope this helps

How can I save a client-side only webpage with text inputs?

I have made a simple webpage with a Javascript backend. I want the user to be able to enter in a bunch of data in form fields, and then save the page. PDF, HTML, doesn't matter, I just want to be able to save the page WITH all of the user's data.
This has to be client side only, I don't want people to have to setup a server just to use it.
The browser's security mechanism does not allow you to create files barring cookies. So may want to google JavaScript cookies and how to use them.
Have two pages, on your first present the form and submit it to the second page using (keep the method get:
<form action="second_page.html" method="GET"> <!-- Other stuff --> </form>
GET will send data as a part of the URL to the second page.
On the second page parse the URL to get the variables set by the user, you can use something like this. Use DHTML/JavaScript to display the values thus fetched into the format you may wish.

How to intercept and add parameters to POST using javascript and ajax?

I have a pretty standard upload form - user picks a file, then hits the upload button. But now I need to add data to the post - after the user picks the file, but obviously before the post leaves the browser. Note that the post is a direct post to a third party (Amazon S3).
Is there a way to make a form with a file picker (or something that looks like one), then the user picks a local file, then hits a button, => javascript calls my server, gets a response, builds the 'real' post and then sends this new post to a third party server.
Basically, until the user picks the file, I don't know a few things (mime type). I know that browsers send this info, but Amazon AWS pre signed posts ignore what the browser says.
I can hit my server (ruby sinatra) with an ajax call from the javascript, which will return some JSON, etc to the script, which will then post to Amazon S3.
My problem could just be my newbieness to javascript...
You can add hidden fields to the form with the file in it. Do your intermediate request, fill the hidden fields. Submit the original form.

Export JSP output to a PDF on click of a button

I have created a JSP with various fields. I want to provide an option to export the page to a PDF before submit but after the user fills in the form.
How can this be achieved? I am struggling with this problem past many days and not able to get solution.
You might want to look into the FlyingSaucer project. It's a mechanism for producing PDF files from XML documents, and in particular from a fairly strict XHTML doctype. It really works quite well, and it supports some CSS3 features for doing things like page headings, intra-document bookmarks (like links), and is generally pretty well-behaved about CSS rules. I don't think it does forms, but you could probably fake that if it's going to end up as a non-interactive document anyway.
Link: http://code.google.com/p/flying-saucer//
(If it's not clear, this'd be a server-side solution. The form would have to be posted, and your server would build the PDF and ship it back to the client.)
Or just use AJAX to submit the form. The use clicks "Generate PDF" or whatever and an AJAX post is made to send the form data to the server and return a generated PDF. That submit can go somewhere else than the service/servlet which is processing the form data.
Just use the Print option in Firefox 3.5. It has an option to print to PDF file. Alternatively, you can use PDFCreator or some other virtual printer software that writes to PDF file instead of printing on paper.
I want to provide an option to export the page to a PDF before submit but after the user fills in the form.
This is not possible at the server side as the information isn't submitted to the server side yet. Your only resort is the browser capabilities and the knowledge of the user how to use them.
If you can live with changing the flow to submitting into some result page and providing an link to export the current result page to a PDF file, then combine this answer with iText.
If you are trying to output a report you can look at display table: http://displaytag.sourceforge.net/1.2/. It comes with a simple servlet filter that will allow you to click a simple link and export to pdf, excel , etc.

Categories

Resources