Converting a xml file into jrxml file - java

Is there a way I can convert a xml file to jrxml file?
I am doing a project where I need to write data from the database in a MS Word file that is already designed with the required template. I have converted that document file into xml format.
I am using iReport to generate the resultant doc file. But it requires a jrxml file. It fails to read from xml file.

Bijil,
JRXML is a template that contains the format for the content that is shown on the report.
And from what i understand the xml is containing the input data.
How jasper reports work is, you create JASPER file by compiling the JRXML file (this can be done using iReport or through your java code). To this JASPER file you will attach a object from your java code that contain data for filling the JASPER.
Please see this link for details
Edited: iReport is a designer tool for creating jasper reports, I am not sure if there any tool that can convert xml to jrxml. jrxml will contain the syntax with respect to jasper report.
What we used to do, were try to create a similar report(by comparing the look and feel) as the one client has given using iReport and get the final jrxml.
Compile jrxml in iReport check the look and feel with the sample word doc with the generated sample report
Then use the compiled jasper file in the application directly. The use of jasper has 2 advantages,
you can use unicode characters in your report
you reduce the overhead of compiling your code every time before generating report.
disadvantage
you need to keep separate track of jrxml, to fix any defect on
previous jasper file.

Save your MS WORD file (Template) in report directory and using Apache POI,
Do necessary edits to your template. Then save your file to any place you like.
Apache POI tutorials
Link 01:
To print save your edited file in temp directory and call Desktop.getDesktop().print(file) using desktop
Link 02:
Wish you good luck.

Related

Generate PDF or Similar to it

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.

Generate PDF files using iText and apache velocity template(.vm)

What is the general workflow to generate a PDF using iText and an Apache Velocity template file (.vm) in Java?
I am interested in knowing steps like: parse template file, put Java object in context and steps to be performed to generate pdf etc.
I know this is a very basic question. But I am not able to find even a single example of this type on the web. I found XDocReport, but I am interested to know other alternatives as well.
Please help me with some sample project link or at least the steps to get started.
Yes, you can.
It all depends on how complex you want the PDFs to be.
Here are the steps for basic functionality
Generate a HTML file using Apache Velocity template file (.vm).
Use com.itextpdf.text.html.simpleparser.HTMLWorker (deprecated) to parse/convert that HTML file into a PDF.
Additionally, you can use com.itextpdf.text.pdf.PdfCopy.PageStamp to add content (borders, stamps, notes, annotations etc) to an existing PDF.
There is also com.itextpdf.tool.xml.XMLWorker for more advanced HTML conversion (adding style sheets etc)
Generating PDF using iText and an Apache Velocity template file (.vm) in Java directly is not possible because:
PDF is binary format,
Velocity generates plain text content.
On other words, Velocity cannot generate PDF.
XDocReport is able to generate a docx/odt report by merging a docx/odt template which contains some Velocity/Freemarker syntax with Java context. The generated docx/odt report can be convert it to pdf/xhtml.
It works because docx/odt are a zip which contains several xml entries. If you unzip a docx you will see word/document.xml. In this entry, you will see the content that you have typed with MS Word. word/document.xml is a plain text, so Velocity can be used in this case.
Here the XDocReport process to generate pdf from a docx template which uses Velocity:
Load docx template. this step consist to unzip the docx and stores in a map each xml entries (name entry as key and byte array as value). For instance map contains a key with word/document.xml and the xml content of this entry as value.
Loop for each xml entries which must be merged with Java context. For instance word/document.xml is merged with Java context by using Velocity and the result of merge replace the word/document.xml value of the map
Rebuild a new docx by zipping each entries of the map.
At this step we have a generated docx (the report).
To convert it to another format, XDocReport provides a docx-to-pdf converter based on Apache POI and iText. Here the XDocReport process to convert a docx to pdf:
Load docx with Apache POI
Loop for each structures of POI (XWPFParagraph, etc.) to create iText structure (iText Paragraph).
Note that XDocReport is modular and you can use other converters as well.
At first,we use freemarker template to generate a html file,and then render html to a pdf file by IItextRender .Finally, we can view pdf file in browser,there has a very useful javascript tools called pdfjs. Maybe you can try it.

Generation of pdf file using java

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/

how to generate a report from jsp in pdf format using jasper

In my application I can connect to a database and get an array resultset and using JSP code I can iterate through the array and can display the report in my webpage using HTML.
I want that the generated report in my HTML webpage can be exported in PDF format and saved in some .pdf file.
Please tell me how to implement such technique to implement such exporting technique.
You can use the PdfWriter class that comes with this package, which includes a quick tutorial from IBM on how to use it:
http://www.ibm.com/developerworks/opensource/library/os-javapdf/

export a report in ms word(97-2003) without using RTFExporter in jasper reports

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.

Categories

Resources