how to save a jsp page as pdf in java? - java

I have a page that built with JSP, struts.This page loading with dynamic content.
I want to save the page as PDF-file with all contents and the same format with a button click. If i can save the page with all contents, I can convert to PDF.
How to save a jsp page with this properties as pdf?
thanks in advance

I was researching this topic lately and I found that better aproach is to use javascript on client side to generate PDF.
There are few libs who can make it for you. choose your way:
f.e.
Generate pdf from HTML in div using Javascript
http://html2canvas.hertzen.com/
https://github.com/MrRio/jsPDF
(:

Related

How to convert html, css to PDF using Java?

I was wondering what are some good tutorials or logic on how to convert HTML and XHTML web pages to PDF using Java?
And also suggest me How can I convert html, bootstrap css to pdf using Java?
There is a library named wkhtmltopdf (https://wkhtmltopdf.org). We used it in our project.
wkhtmltopdf command line utility must be installed on a machine.
Download page: https://wkhtmltopdf.org/downloads.html
Note it also must be installed on servers your app will execute.
Your code should fetch html and css. Css should be added to html header in style tags. I'm not aware of possibility to fetch it as a separate file to html.
Next step is to convert your html to a PDF. This code will produce byte[] containing your PDF.
String html = "<...> your html";
Pdf pdf = new Pdf();
pdf.addPageFromString(html);
pdf.addParam(new Param("--disable-smart-shrinking"));
pdf.addParam(new Param("--header-html", headerPath));
pdf.addParam(new Param("--footer-html", footer.toAbsolutePath().toString()));
return pdf.getPDF();

Extracting web page with jquery content data

I need to extract data from particular websites, say it a comment section in a website. What i already tried is extracting html text using jsoup, but since the comment section used jquery it only extract the jquery code not the comments text. Any suggest to solve my problems? thankyou
You can use HTMLUnit to render the page with all needed content and then extract data from build DOMTree. Here you can find info on what to do if AJAX doesn't work OOTB.

How to generate the PDF in CQ5.6.1 using page content in cq5

How to generate the PDF in CQ5.6.1 using page content.
A button in my site (genarate PDF) on click of the button i have to genarate the PDF file using the same page content.
Please let me know is there any out of the box PDF genarator in CQ or do i need to get the any linsenced product to genarate the PDF.
Thanks..
Adobe CQ is integrated with the Apache FOP, a formatter able to create PDF files. This tutorial describes how to enable content rewriter providing PDF version of the content under the .pdf extension.
However, please keep in mind that this approach requires manually writing the XSLT transform file able to process your page (and every component on it) and output the XSL-FO document.
In a previous project (CQ 5.5) we used https://code.google.com/p/wkhtmltopdf/ to create PDF files.. worked pretty good!
I had used Phantomjs to create a a custom pdf from the cq5 pages. for example if you don not want to display the right trail in the pdf or you want to disable the header footer. all this can be achieved with the help of phantomjs.
create a servlet which will execute a command at your server.
phantomjs <custom.js> 'page_url' nameofthepdf.pdf
here custom.js will show or hide html content based on your need.
This will work for all pages irrespective of cq5 or any tool.

use jsoup get comments from html and save as XML file

I need the help!
Go to page: http://www.tweetfeel.com/
Then type in "linkin park",Used jsoup get all user comments saved as xml?
I'm used java with netbeans.
Not sure if this is possible with jsoup, since the content is generated dynamic by javascript.

Displaying Microsoft Office Document(word, excel etc) in JSF Page or HTML

I got to display documents in web page instead download it. There are HTML 5 components(object, iframe) for pdf but office document. Is there a way to display Word, Excel etc. documents on JSF page or HTML.
Web browsers cannot natively display Microsoft Office documents.
The solution is usually to generate them as PDFs on the server-side, then allow the user to view them (if that have the PDF plugin) or download the file.
If you are working with OpenXML documents (.docx, etc...) you can use an XML Parser to obtain the content and display it as you wish.

Categories