I am displaying few tables using HTML table tag and CSS . I am using Struts 2 and would like to include the "Export to PDF" functionality. Right now its just one page where i have to use this. Later one there will be one or two more page where i have to use this feature. I am Looking for some easy to implement available plugins or jar or anything that can be used to do that.
There is a Java API for generating PDF.
Here it is: http://itextpdf.com/download.php
Call it from you Servlet or Struts Action, and use HttpServletRersponse.getOutputStream to direct the PDF document back to the browser.
Related
I am developing a web application and when I want to add some functionality I find a problem:
-I offer to my clients the possibility of see a page called "Product details" with: the description of this product, product´s name, an image of the product... and I want to give them the chance of download a PDF file with (more or less) the same data.
The problem is that I am using Servlets and JSP so if I want to create a PDF from my HTML page I must take the "final" page.
So my question is:
-Is there a way to create a PDF automatically from a JSP in Java?
In a project I'm working on, we're using BIRT to generate some HTML reports from some XML Traces.
However these reports are pretty simple and ugly and we wish to improve them. We made a mockup/template in HTML/CSS (and some JavaScript that we want to be embedded in each reports) but now that we're happy with the design, there seem to be a problem (that we should have seen before):
Can we use this template with BIRT? AFAIK, we have to design the birt template using birt's tools ; and it'll be a lot of (useless) work to do so, and we're not even sure we'll be able to obtain the same design with birt as we tweaked things very tightly with CSS.
You can give bookmarks to all of your visualizations in the BIRT report and then use the JavaScript API to display the content in your template. Alternatively, if you are building even the visualization in the HTML template, you can use the REST API to extract data into JSON format and then visualize that as you like in your HTML pages.
You could also load the external CSS file with the BIRT report.
I am developing a Java Web Application (jsp/servlet) using tomcat. I need to display pdf file from local machine. can you suggest what is best way to display it?
I used iframe to display pdf file.
<iframe src="resume.pdf" width="100%" style="height:60em">
[Your browser does <em>not</em> support <code>iframe</code>,
or has been configured not to display inline frames.
You can access the document
via a link though.]
</iframe>
I think you can try a Library called XPDF , I think you can convert from PDF to HTML page , or the second option is just let the user open a link to the page (www.yourwebsite.com/pdffolder/somepdf.pdf)
If you need display a pdf file using tomcat, you can access directly to the file using the specific url where the file is located in your navigator, depending on the path where you put the file, so you can access using 127.0.0.1/files/test.pdf for example. If you need generate a pdf, the best tool I think is iText, this is an easy example how to use id: Introducing PDF and iText
I have a HTML file containing some java script tags. When I run this file in some browser such as IE, some contents are cached from its source and displayed on browser(for example weather of some cities). How can I run run this html file and get contents of web page that was displayed on web browser before? I don't want to display contents on my application; I want to parse returned data and extract some special contents(for example extract weather of each city).
can anyone guide me please?
What you're trying to do is called html scraping.
Your best option is to get help in the form of a library, since this is a conmon and complex task.
See this question: Options for HTML scraping?
Selenium is a good bet. It supports HtmlUnit, Firefox, Chrome amongst other browsers.
Link: http://seleniumhq.org/
I have some PDF template (with header and footer). I want to generate documents that are based on that template.
Is there any way to do that with iText? Thank you
P.S. Right now I am generate a document on-fly i.e. every time I generate header, footer and the context itself.
UPDATE: I have found incredible library called PD4ML. It's not free, but not such expensive, BUT it has really cool features such as HTML2PDF conversion on fly, supports a lot of HTML-CSS tags and has even its own jsp tags library! So I really suggest it when you need something instead of heavy and memory-eating JasperReports.
You can use JasperReports library and the iReport visual designer.
JasperReports use iText to produce PDFs from "jasper" templates, that are XML files (following the jrxml DTD) compiled in java classes, but allows you to use the template for generating MS Office files (with POI), html, etc.
Im not sure with iText, but you can use BIRT for this purpose. http://www.eclipse.org/birt/ Its too much using it just for PDF creation, you can do a lot (more than you can imagine) with it.
If you can choose your template format. I would go with JODReport and JODConverter.
JODReport use an ODT template and fill the mapping in the template with your java code.
JODConverter use LibreOffice to convert such template in PDF or whatever fortmat LibreOffice can handle to export.
You have to be able to use LibreOffice as a service installed remotely on a machine.
I used it back in 2012 but not sure if the project is still active