Rendering and Printing RTF in Java - java

I've been trying to locate a decent RTF editing and printing solution in java that we can plug into our application.
Looked at the RTFEditorKit however it seems to fail at rendering more complicated (and less conforming) RTF documents.
Also worked a bit with iText but it seems to not support printing. (not to mention support for RTF has been removed in later versions)
Really trying to stick with RTF as that's what our client base is used to, but i'm open to ideas.
Does anybody else do this? How do you do it?
Thanks for any help and suggestions.

Suggestion:
See how good OpenOffice (or its successor, LibreOffice) works with your particular mix of .rtf files. If OpenOffice/LibreOffice works, then just use it's (Java-ready) API.

Try to use the kit to open your RTF
http://java-sl.com/advanced_rtf_editor_kit.html
And this component to print
http://java-sl.com/JEditorPanePrinter.html

Related

Java utility for printing PDF

I'm making a utility to grammatically making a document and printing it.
I am gonna apologize, I'm not good at formulating this and there may be some confusion, please bare over with me :(
This project is mostly for making a user friendly utility for creating documents in your program and printing it and also as a learning experience.
It uses objects which I will convert to MarkDown as its easy to work with, I convert it to HTML as its going to be used in a web form.
The problem occurs when I want the program to print this HTML file that i have now created to a PDF.
I've searched for a solution for a very long time but have yet to find results, all that I've found was either out of date, filled with bugs or just could not do what I wanted.
I have tried iText as that seems to be the most popular choice but as stated above, everything I found was out of date and no longer useful, mostly because the classes they speak of do no longer exist.
What I do want is eventually independence of other libraries so that is my ultimate goal, but for now I want a way to print a locally stored HTML file as a PDF, it needs to be CSS compatible.
As an extra thing if anyone could point me in the direction of learning how to make MarkDown to HTML and printing HTML to PDF I would be more than happy.
Edit 1:
Stephan C pointet the question is too wide and difficult to answer, I will try to explain:
Main thing I want is to print a PDF file using an HTML file and CSS which is stored locally.
Optional solutions is I would love to learn how to code this myself instead of implementing libraries, for example markdown4j and iText. Yes I know that's a lot to take on, but as stated this is a learning experience for me.
Have a look at Converting HTML files to PDF. It has sample code for using with iText and also other suggestions. If you run into problems with approach suggested post specifics here. Either modify your original question or ask new question.
Printing directly from HTML to pdf can be also worse than using iText or other libraries.
I just made some iText PDF not using low level pdf classes but compiling a PDF form from it.
If you need to fill a PDF form, you can use iText as following.
Make your html form a PDF form. (acrobat or other free softwares)
Use iText classes AcroFields to get the PDF form fields (you get them by names or you can return a map of fields using AcroFields.getFields();
Compile the required informations using AcroFields.setFields() or .setField();
PdfReader class allow you to open an existing PDF (the template)
PdfStamper allow you to write the stream to another one (the result)
Adding images and other binary stuff is really easy!
By this way, you can do it quickly and layouts will be fast and good too.
The limit is that you need as many template as many data you need. (if you have fields that is some cases are many in other just one, you need twice templates).
For a static number of fields is a good solution.
Hope it helps.

Java library for PDF reader supporting highlighting

I would like to build my own pdf-reader in Java and would like to have the possibility to highlight words in the pdf and save these highlights.
I have seen there exist several PDF libraries I can use, but I wonder which would be best to use for this purpose.
Is it possible to do this kind of highlighting, and is there a specific library or so to help me do this?
Any help is greatly appreciated!
Here you have a big list of Open Source pdf libraries for java. I haven't used any of them but I'll bet for pdfBox that's part of Apache Foundation. It has a specific class to highlight PDFs in xml but I think you also have to rebuid them.
Use Apache Lucene Library. It provide highlight option for search terms.
You can use Apache PDFBox for highlighting in PDF.
Link: https://pdfbox.apache.org/

Adding buttons, textfields, checkboxes etc. to an OpenOffice textdocument usind UNO with Java

I am trying to create a OpenOffice document using the UNO-API with Java.
I am already able to create a simple document and put some simple text into it.
What I want to do, i.e. need to do, is add also Forms (TextFields, CheckButtons, Push(Click)Buttons) into it.
The idea is to create a form in openoffice which in the end can be transformed to a PDF with interactive pdf-forms.
I am able of creating these with iText and manually with OpenOffice.
But I have not found a (simple or any) Example of creating such objects with the UNO-API.
So any help, hints or links (not that I haven't tried to find something via google, but maybe I just used the wrong key-words) is appreciated.
An alternative for you might be to use the ODF Toolkit, with its Java APIs for manipulating ODF documents, the native format of OpenOffice.org and its descendants.
I don't know if ODF Toolkit supports the features you are interested in though. Check at http://incubator.apache.org/odftoolkit/

How to convert HTML ==> RTF in Java?

The basic API of JAVA that uses RTFEditorKit and HTMLEditorKit, is not able of recognize tags like <br/> and <table>.
So I have searched on internet a better way of converting HTML to RTF and i have found two solutions that seem to work.
JODConverter and HTML-to-RTFconverter. The first one needs OppenOffice installed to work and the second one uses DLL, so it can’t be used on Linux.
Does anyone know about other solution?
Thanks for any help!!!!
Do they want it in RTF or do they want it in Word format? There's a big difference.
Ensure your editor is generating XHTML (or convert it yourself with jtidy, htmlcleanup etc) then download the content as an XHTML but with a .doc extension and the MS Word mime type. Word 2003 or higher will open it as a word doc.
If it is valid html, you can use Apache-FOP.
There are stylesheets for transforming html to FO.
Apache FOP can write PDF and RTF as well.
http://www.torsten-horn.de/techdocs/java-xsl.htm#XSL-FO-Java
http://html2fo.sourceforge.net/index.html
You can take a look at RTF Template (http://rtftemplate.sourceforge.net/) Don't know if it fits your needs, but I used several times under Linux and was OK.
I already used the html-to-pdf and got the expected result. I have helped.
By RTF conversion there is an important issue to care about: a target RTF viewer. All of them declare RTF support, but, for instance, Notepad.exe can only show images in WMF format, it does not display headers and footers. TextEdit on MacOS can only deal with images embedded as a kind of active objects and has troubles with tables, OpenOffice is not tolerant to minor markup inconsistencies etc.
My favorite tool for HTML->RTF conversion is PD4ML - it produces clean, almost human-readable RTF markup and successfully solves another challenging problem for RTF generating tool - a support of nested tables (if you work with HTML - they are everywhere).

Design PDF template and populate data at runtime using java,xml etc

well i have been looking for a java based PDF solutions...we dont have a clean way i guess-still.. all solutions are primitive and kind of workarounds... No easy solution for this requirement -
1. Designing a PDF template using a IDE (eg. Livecycle designer ..which is not free)
2. Then at runtime using java, populate data into this PDF template...either using xml or other datasources...
such a simple requirement and NONE has a good "open-source and free" solution yet ! Is anyone aware of any ? I have been searching for since 3-4 years now..for a clean way out...
Eclipse BIRT comes close.. but does not handle Barcode elements ..OOB.
Jasper - ireport is also good but that tool does not have a table concept and is kind of annoying ! Also barcode support is not good.
XSL-FO has not free IDE for design .
Looking for a better answer .. got one ?
If it's a "simple requirement", you could create a report designer around iText and release it as FOSS yourself.
What are your key requirements? Does your input have to be a PDF? If so, you'll be probably working uphill for a long time still. Obviously you want to inject data and output a PDF.
If your templates can be something other than PDF, you could try using the OpenOffice API to get OpenOffice to do manipulate documents and produce a PDF. JODReports or Docmosis would be better ways of interacting with OpenOffice and Docmosis allows you to treat documents (doc and odt) as templates.
You can create a PDF file with AcroField through iText API AcroField values can be populated.
Note: Using OpenOffice you can create PDF document with FormFields.
http://blog.rubypdf.com/2007/08/01/freely-fill-pdf-form-with-the-help-of-itext-or-itextsharp/
You could use OpenOffice's UNO API. It looks rather heavyweight but at least you get something full-featured.
Have a look at XDocReport. You create your templates in word .docx or OpenOffice .odt files, then turn them into populated PDF files with Java code.

Categories