File previewers for PDF and Docx - java

I would like to have a preview of a .pdf, .docx or .doc file inside a JDialog. But I'm unable to find previewers that allow nesting of such previews inside a Swing application. Alternatively are there any previewers that can transform such files into .html and then display them in a TextPane.
Fidelity isn't that much of an issue as is embedding and ease of use. Also I don't require one tool to be able to preview all types of files.

That's a tough one because of the formats you're dealing with. You might want to try ImageMagik for PDF -> image format for display in your TextPane. If that works well enough for PDFs, then you could use JOD Converter or Docmosis to get from Doc -> PDF then ImageMagick again for a display image. JODConverter and Docmosis are based on OpenOffice which can do pretty rough html / xhtml output as another option for display. The latest version of OpenOffice can read docx also, meaning all your bases are covered, and if fidelity is not too big a deal as you've indciated, then JODConverter/Docmosis and ImageMagick might be a combo you can use.

Related

Preview LaTeX output with Java

Right now I'm working on displaying LaTeX generated document with Java.
Strictly speaking, LaTeX source can be used to directly generate two formats:
DVI using latex, the first one to be supported;
PDF using pdflatex, more recent.
However rendering dvi or pdf is not available as far as I know.
Is there any way to handle those formats ? Or maybe others that makes sense ?
There are not enough details with regards to how you wish to "render" DVI or PDF from a LaTeX document. However, you could always just render the pdf using pdflatex and DVI using latex and use ICEpdf for viewing PDFs and javaDVI for viewing DVIs.
Another neat hack to display pdf in a panel is to pass the file path to an embedded web component in the application, and the web component will use whatever pdf rendering tool is available on your machine (Acrobat, Foxit, Preview, etc.)
I remember there was a post about this a long time ago.
I don't think there's a generic way to preview the rendered output without generating the file itself. You can write your own LaTeX engine which caches the output every few seconds and displays that but regardless of the storage, you have to output it somewhere physically and then render the output separately using any of the steps mentioned above.
Another approach is to convert the div output to an svg image file and render that with SVGGraphics2D. That will produce nice scalable results. Dvi files can be converted to svg on the command line (or in a script) using:
dvisvgm --no-fonts input.dvi -o output.svg
For more conversion options see this thread on how to convert pdf to clean svg.

Java DOCX file Viewer

Currently I'm developing an application that allows users to create a template and generate it into a DOCX file. The application needs to be able to display to users the changes in the template as the user is creating it.
The approach I tried was using DOCX4J library (allows manipulation of DOCX file) and ICEPDF which is primarily used to display the DOCX into the swing component by converting it first into a PDF file. Now the problem in this approach is that it loads pretty slow and some of the changes that occurs in the DOCX file does not reflect on the PDF conversion (example: dashed underline, font changes). When I tried to open the DOCX file ouput in MS WORD, the file is viewed correctly so I know changes do occur, but it seems that ICEPDF just can't show it properly.
So I was wondering if anyone knows a java library that allows DOCX files to be viewed directly from a Swing Component instead of converting it first into a PDF file.
You can try docx4all or DocxEditorKit. Both of these are built around docx4j.

Java generate PDF from RTF

I want to generate PDF file from RTF file.
I have tried following.
Itext
It's already outdated and new version doesn't support rtf.
JDocConverter
It uses OpenOffice on the background. it is working fine, there is only one problem. Open office doesn't support drawing object in RTF.
Any other possible and reliable solutions?
Note: It would be fine don't use any commercial software.
Windows has native convert RTF to PDF using command line, however it will to a degree be limited, so it will use direct convert text and images, but it will depend on rtf syntax as to which drawn objects are supported. WORD ART drawing objects need MS Word to print
The output looks reasonable but here is the source in MSWord where the art was clearly not handled by the non-word printout.
Under Windows you could print to CutePDF Writer. This freeware uses Ghostscript as a back end.
You may try Aspose.Words for Java to convert RTF file to PDF format. You can load a file in RTF format into Aspose.Words for Java and then save it to PDF format. Please note that while loading specify RTF as LoadFormat value and pass PDF as SaveFormat value while saving the document. This doesn't require OpenOffice or any other software to be installed for the conversion to work.
Disclosure: I work as developer evangelist at Aspose.
Best way to do it is use MS Office. And Ms Office is able to save file in PDF format (you need install some addons I think).

Java: Embed a HTML or PDF into a JFrame

I am open to alternative solutions, so here is my problem.
I have 111 PDFs that contain information on various degree programs. I can convert them to HTML using freeware.
The problem with the HTML is that it contains CSS, JEditorPane doesn't display the webpage, and the PDF libraries are slow and bulky.
I want to have a JCombobox where users can select a page to view, and have it appear below the box.
Any ideas on the best method?
Use iText API for PDF and DJ Project for HTML/webPage.
Most libraries that convert PDF to HTML can also convert PDF to image.
If you can convert to SVG and display it using one of the SVG libraries (E.g. Batik), that would be one way you could display it without losing any functionality like zoom in/out.
Otherwise you can convert PDF to high-res JPG/PNG and display it in your app.

Generate Save Convert to TIFF PDF

Please point us in right direction
We have a requirement to
Generate a PDF
Edit/Enter some fields on it
Save/Print the information
Should have a button on the pdf "Convert to TIFF" that should generate TIFF image of that PDF
I am sure we can do 1 and 2 very easily, we are planning to use iText API.
We dont have any clue about 4.
Experts if you have any idea please let us know.
We are using Java
There are lots of programs which do PDF to image conversion (both Open Source and Commercial). You can also use icepdf, Jpedal, Qoppa and PDFRenderer
You can create, edit and fill PDF form fields using Gnostice PDFOne. PDFOne can also print PDF documents and forms. Existing documents can also export PDF pages to image formats. For exporting to TIFF, you will also need for Advaned Imaging IO library from Oracle (Sun). Disclaimer: I work for this company.
If you want a button on the PDF to export the document to TIFF, then that is not possible, as PDF specification does not describe such a feature. As mentioned earlier, any PDF document can be converted to image formats including TIFF.
DISCLAIMER: I work for Gnostice.

Categories

Resources