Export JSP output to a PDF on click of a button - javascript

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.

Related

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 to save changes on website with textbox

Im new at web developing.
I want something like:
A website, that everyone can enter. on the website u have 2 parts: one is filled with textbox so any user can write something in it and click button 'save comment'. He other side is filled with the execution of that button(it displays added text comment -but not just for a moment but that text is saved on that website). Simple as that...
Do i use java script?
Ive been looking for the answers but kinda didnt know how to ask gooogle bout that
scheme on that website:
----------------------/----------------
-textbox--------------/--constant text-
--add comment button--/--wrote by user-
----------------------/----------------
You have many possible ways to do that. One of the ways is to use html with jquery and send the result via web service (.asmx for instance) and save that result in a database (MSSQL for instance). So everytime you load the page you can get those saved results and display it on the relevant page. Another way is to use php with mysql or to use java...
If you don't want to use databases and server side code you can save the results in a cookie and then display those results in the page.

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.

Popping up a window for the user to show some data?

I have a webapp where my users might want to get some data from me in xml format. The flow I was thinking of:
User clicks a button named "export"
I generate a long xml string using javascript.
Pop up a new window and just paste the xml string into it.
I would prefer saving the xml string into a text file for the user, but I don't think this is possible with javascript (security reasons).
Are there any other best practices for doing something like this? I guess this will work fine,
Thanks
You can add a hovering text field to the page and paste the XML into that. To make things more simple for the user, set the focus to the field and select everything (so they only have to press Ctrl+C).
If you can access server-side pages, you can generate the XML string using javascript, make an ajax call to give the server your string, then make the user download the generated file.

How to do nice and simple file uploading in javascript?

All I want is:
select a file
small progress bar (unless it is not simple)
fail/success confirmation on client side
trigger action on server side.
all that without page reloading
Except that, the simpler the better.
Snippet would be most welcome.
There are plenty of scripts and tutorials around. Check for example http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html
Apparently that's not as trivial as one might think, since you can't just take the body of a form, containing an <input type='file'/> tag, and submit that.
But you can submit the form with a target of another <iframe/> and then poll the server with a XMLHttpRequest object for status updates, that however, requires that your sever-side script, that handles the upload, does so in a asynchronous manner, otherwise you will only get a status update once the file has been fully uploaded, not the kind of progress status updates you want. I think this is a challenge for most web frameworks to date, but I have never actually had any reason to dig into it. Sounds fun though...
If you just want to submit the file, independently of the actual form, you'll do the same, but you don't have to worry about the progress status updates.
What you can do, is to replaces the <input type='file'/> once the upload completes, with a <input type='hidden'/> containing the server-side ID of the recently uploaded file. That way you'll know when the user hits save, what files you'll want to actually save.
That hidden thing can also be a checkbox, which would let you undo a file upload, by simply unchecking that checkbox before hitting save.
File uploads using the XMLHttpRequest object is not possible in all browsers (only Firefox and Safari/Chrome support it), so for a cross-browser implementation use the <iframe> trick.
If you want a real XHR file upload, I have written an extended article on how to do it in Firefox 3. It's so low level that you actually have to build the actual HTTP request from JavaScript strings.
Maybe GearsUploader will fit.

Categories

Resources