Generating letters in Java [closed]
I need to generate some business letters in Java, with some dynamic information like address, to,from etc. Remaining letter content would be the same. These letters are not displayed to the user but are directly printed. I know i can do this using Jasper Reports i.e generate pdf & print it. Does somebody have any other suggestions for this?
You could use a PDF-tool like iText. iText lets you create pdf documents from Java or .NET.
FreeMarker is perfect for the generation. You would probably then use some other library to convert to a printable format and print.
If you want to create PDFs, I recommend Apache PDFBox. Examples are available here.
If you're up to it, you can use a few freely available libraries to construct your own system where the user can provide the templates in a Word (or Writer) format. Several options are available to do the merging of data with the template but basically it comes down to opening the document as xml and replacing custom tags (or the ones used for the mailmerge function) with the data. You could implement FreeMarker for the custom tags (see Mike's answer). Libraries that cross my mind are:
- OpenOffice API
- Docx4J
- Apache POI
There are plenty of experienced users here on SO for these (and other libraries) so any problem you encounter will surely get a decent followup.
Cheers, Wim
In answer to your template comments, JODReports or Docmosis might be useful. They work over top of the OpenOffice API (as per Wivani's response) which can be hard to use directly.
精彩评论