I am developing a standalone application in Java. I want to generate a pdf file using Java code. I have a display form in which all the details are fetched from database and displayed in the window. Details are Customer Name, Order Details etc.
Now I want to have a button there which says Convert to pdf.
I want to convert this to pdf file with proper alignment and formatting like tables, font etc.
What can be an ideal way to go about it?
I'd suggest you to use reporting tool like a jasperreports.
JasperReports is entirely written in
Java and it is able to use data coming
from any kind of data source and
produce pixel-perfect documents that
can be viewed, printed or exported in
a variety of document formats
including HTML, PDF, Excel, OpenOffice
and Word.
Have a look at other open source projects (pdf api):
Apache PDFBox
Apache Tika (Toolkit for detecting and extracting metadata and structured text content from various documents using POI and PDFBOX parser libs.)
PDFjet
Use iText:
http://itextpdf.com/
Related
I'm creating a JAVA application
and I want to create and display and print a PDF file.
Like this example:
http://img11.hostingpics.net/pics/331702Sanstitre.jpg
So can you give the right way to do it ?
I mean is this a pdf file displayed into a JPanel or something else ?
and thnx alot.
For working with PDF files I would recommend using a library such as Apache PDFBox which has the ability to write, read, and print PDF files using org.apache.pdfbox.PrintPDF
The API can be found Here
As for displaying it in the JFrame, you can simply read the text and print it out in a Swing Text Area
For generation of pdf files you can use Jasper Reports library. It is popular API for creation pdf files from template in which specific data is inserted. Template files have ".jrxml" extension and can be created and edited by Jaspersoft Studio. These files look like forms with variable fields, this is very useful for generating different kinds of reports.
The API for Jasper Reports Library can be found here.
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
Which APIs in java help in extracting table metadata from a pdf, and presenting that table in a web page?
The result should be that when the source of page is viewed it will show the html code of that table.
Itext is usefull in this context
http://itextpdf.com/
I assume that, you need a PDF library for Java.
PDFBox is one of the popular libraries created to PDF manipulation and I think it is worth to look at it.
try The Metadata Extract Tool which extracts metadata from specific file types including PDF. Then you can parse the xml output with any Java XML parser. Once you're able to parse it, elements can be easily laid down in your view page.
I was looking at using iText to create both a pdf and html version of a document with RTF as a possible option. According to this question this is no longer possible with iText. Is there a library that will allow me to create a document in Java and output it as both PDF and HTML? The ability to output RTF would be nice but is not required.
As that answer to the other question states, you can just use the iText RTF Library.
I have used PD4ML to convert HTML to pdf. Even though it is a commercial app. It is very reliable and supports CSS well.
JasperReports. If you look at this package it supports export to:
pdf
html
rtf
xls
xml
You have two options to create the documents:
via iReport - a visual designer for reports
via an API, where you construct everything with Java code.
Note that even though JasperReports's main function is to create reports, it can very well create other documents, with no tabular data for example.
You could also try Docmosis since that supports the output formats provided by OpenOffice (including the ones you specified) and you can often do the job with a lot less code.
I have a report which needs to be exported in pure word format(97-2003) using jasper report. But Jasper uses RTFExporter for exporting report in doc format, wen i read the report using POI, it throws error saying its not pure word. Can anyone help how to generate a report in word using Jasper reports. Please help!
I'm pretty sure you can't do anything closer than RTF from Jasper. If you can't replace the Jasper report, then you need to find something that will read the RTF and render it as a DOC.
You could use Docmosis to read the RTF and spit out a DOC. Docmosis is based on OpenOffice and Java and OpenOffice has pretty impressive filters for saving in different formats. Also, most platforms are supported since you haven't mentioned any limitations on what type of system you are running on.
Aspose.Total will allow you to generate .doc files from Jasper.
Aspose.Words for JasperReports is the
only known solution on the market that
makes possible exporting reports from
JasperReports and JasperServer to
Microsoft Word document (DOC), Office
Open XML (OOXML, DOCX), Rich Text
Format (RTF), OpenDocument Text (ODT),
Web page (HTML) and plain text (TXT)
formats.
It looks quite expensive, though.