Recently I am working on commercial project which requires to generate a PDF based on some dynamic HTML content, now I have implemented that with a java library called WKHTMLTOPDF (http://wkhtmltopdf.org/).
This library is a command line tool which user browser webkit as rendering engine, since I am new to java development, I am not sure whether there is any security or performance issue when using this library.
If this is not a good solution, is javascript plugin an alternative?
Sorry for my english!:)
I've worked on the same sort of thing recently. I used iText and found it immensely useful. I haven't used WKHTMLTOPDF but I'm answering since you seem to explore more on other options which could be better, safer. iText has been here for a long while now, and it's pretty simple to use.
Follow these links for more info on iText,
How to convert HTML to PDF using iText
And,
Converting HTML files to PDF
A small/sleek tutorial http://hmkcode.com/itext-html-to-pdf-using-java/
If you are concerned about any sort of licensing issues follow,
Is iText 5.4.2 open source?
I found iText quite handy and is supported by a most of the browsers too. (Chrome, IE, Firefox, I haven't tested on res of them) Hope this helps.
I would suggest you to use PD4ML library available purely in JAVA .It is easy to use and generates PDF from HTML (dom) quickly.
http://www.pd4ml.com/
I would like to render/open PDF file (stored in SDCard) in Android without using in-build application or viewer.
1) We have tried MuPDF open source library but rendering using this library is very slow.
2) Can we use iText library for rendering PDF files in Android (i.e. iText as a PDF Viewer).
Is there any other PDF library(open source) that can be used in Android Or suggest basic guideline for developing PDF viewer for Android.
1) MuPDF is good to render textbook pdf in android while it may be slow to render pdf with big images. A lot of customizations and improvements especially memory usage control need to do if you want the MuPDF to run fast and stable on android platform. You can check out two open source projects VuDroid and apv which are based on MuPDF.
2) It's up to your requirements. The iText may be enough to render simple text pdf, but I don't think it has better performance than MuPDF or other libraries that developed by using C/C++.
Another choice is to use Poppler. A successful story is the popular android app ezPDF Reader is based on Poppler, although it's violating GPL license. The out of box Poppler needs more work than MuPDF to do to run on android smoothly. You can refer to the open source project apdfviewer.
I've done some research in this field recently, I've tried more than 14 libraries on Android, I've done simple benchmarking on some high resolution print-ready PDF magazines and I'm currently considering to use MuPDF or Radaee in work as they went out as the best.
I've tried VuDroid and apv as well and they are very unstable, they are crashing very often on complex PDF documents and very slow in comparsion to MuPDF or Radaee.
Since MuPDF and Radaee (and some other libraries) are written in pure C and are used on Android through NDK, they are giving the best possible performance (and they both are paid for a commercial use).
Take a look at my PDF reader for Android here at anddev.
As I remember it uses modified PDFBox (without things related to editing), and features my own font converter (to feed fonts to Android and render them faster).
I don't develop PDF reader anymore and I can make all my changes opensource (though it will require some work, and time). You can try it out to find out how well it performs for you. Note: reader doesn't support encryption and copy-protection.
I'm developing a software (mac & pc) for opening & annotating PDFs for presentations. I need help finding a Java library that can assist with opening an external PDF, that will not just open the text, but the images & formatting as well. Anyone have experience with this?
There's a library called iText that does most things you will need for PDF. I only know it because it was part of an application I modified, so I don't have anything to compare it against.
I did find some of its behavior non-intuitive, so you may want to look around still.
AFAIK iText is to generate and manipulate PDF files. If you want to open and view PDFs use http://pdfbox.apache.org/
Most Java libraries will let you access the low level objects. Your exact requirement is quite vague what exactly are you trying to do?
I want to render MSWord, PDF, HTML, etc to an image (e.g. TIFF) from server-side Java.
Most available products are shareware printer drivers, and so not suited to a commercial server app: I'd like the library which is robust, well-supported, performant, and concurrent.
Any suggestions for open-source or commercial libraries?
Refer to these:
A good library for converting PDF to TIFF?;
Export PDF pages to a series of images in Java; and
Java library for converting Word documents to PDFs or images .
And if you didn't find them in a search don't feel bad, you probably just used the SO search instead of googling for "site:stackoverflow.com convert pdf image java" (etc).
Seems that somewhere in this API, iText, you'll be able to render a PDF to an image. For HTML you may consider Flying Saucer (but the project looks deadish). Shame that JWebPane isn't ready yet.
For MSWord ... no clue.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a new app I'll be working on where I have to generate a Word document that contains tables, graphs, a table of contents and text. What's a good API to use for this? How sure are you that it supports graphs, ToCs, and tables? What are some hidden gotcha's in using them?
Some clarifications:
I can't output a PDF, they want a Word doc.
They're using MS Word 2003 (or 2007), not OpenOffice
Application is running on *nix app-server
It'd be nice if I could start with a template doc and just fill in some spaces with tables, graphs, etc.
Edit: Several good answers below, each with their own faults as far as my current situation. Hard to pick a "final answer" from them. Think I'll leave it open, and hope for better solutions to be created.
Edit: The OpenOffice UNO project does seem to be closest to what I asked for. While POI is certainly more mainstream, it's too immature for what I want.
In 2007 my project successfully used OpenOffice.org's Universal Network Objects (UNO) interface to programmatically generate MS-Word compatible documents (*.doc), as well as corresponding PDF documents, from a Java Web application (a Struts/JSP framework).
OpenOffice UNO also lets you build MS-Office-compatible charts, spreadsheets, presentations, etc. We were able to dynamically build sophisticated Word documents, including charts and tables.
We simplified the process by using template MS-Word documents with bookmark inserts into which the software inserted content, however, you can build documents completely from scratch. The goal was to have the software generate report documents that could be shared and further tweaked by end-users before converting them to PDF for final delivery and archival.
You can optionally produce documents in OpenOffice formats if you want users to use OpenOffice instead of MS-Office. In our case the users want to use MS-Office tools.
UNO is included within the OpenOffice suite. We simply linked our Java app to UNO-related libraries within the suite. An OpenOffice Software Development Kit (SDK) is available containing example applications and the UNO Developer's Guide.
I have not investigated whether the latest OpenOffice UNO can generate MS-Office 2007 Open XML document formats.
The important things about OpenOffice UNO are:
It is freeware
It supports multiple languages (e.g. Visual Basic, Java, C++, and others).
It is platform-independent (Windows, Linux, Unix, etc.).
Here are some useful web sites:
Open Office home
Open Office UNO Developer's Guide
OpenOffice Developer's Forum (especially the "Macros and API" and "Code Snippets" forums).
I think Apache POI can do the job. A possible problem depending on the usage your aiming to may be caused by the fact that HWPF is still in early development.
HWPF
is the set of APIs for reading and
writing Microsoft Word 97(-XP)
documents using (only) Java.
You could use this:
http://code.google.com/p/java2word
I implemented this API called Java2Word. with a few lines of code, you can generate one Microsoft Word Document.
Eg.:
IDocument myDoc = new Document2004();
myDoc.getBody().addEle(new Heading1("Heading01"));
myDoc.getBody().addEle(new Paragraph("This is a paragraph...")
There is some examples how to use. Basically you will need one jar file.
Let me know if you need any further information how to set it up.
*I wrote this because we had one real necessity in a project. More in my blog:
http ://leonardo-pinho.blogspot.com/2010/07/java2word-word-document-generator-from.html
*
cheers
Leonardo
Edit : Project in link moved to https://github.com/leonardoanalista/java2word
Try Aspose.Words for Java, it runs on any OS where Java is installed.
It will output the document to DOC, DOCX or RTF if you need an MS Word output format. All are supported equally well.
Using this API you can create a document from scratch, literally from nodes and set their formatting properties. You can also use a DocumentBuilder which provides higher level methods such as create a table row, insert a field etc. Or you can copy/join/move portions between existing pre created document, say you want to assemble a contract, just grab and copy pieces from several documents and Aspose.Words will merge styles, list formatting etc properly in the resulting document.
You will be able to insert a TOC field using Aspose.Words, but as of today, the TOC field will require a field update when the document is opened in Microsoft Word. However, we are going to release full support for TOC fields early in 2010. E.g. it will build complete TOC as MS Word does it.
I'm on the Aspose.Words team.
It was mentioned only briefly once, so I'd like to call out the docx4j library, as I've had more success with docx4j than anything else. Apache POI's support for Word documents isn't very good. Also, unlike Aspose.Words, docx4j is an open source library.
The only drawback is with docx4j you have to create Office Open XML (docx) format documents rather than OLE2-based (doc) format documents. This is the default format for Word 2007, but Word 2003 and earlier users will need to install a compatibility pack.
Try Aspose.Words for java.
Aspose.Words for Java is an advanced (commercial) class library for Java that enables you to perform a great range of document processing tasks directly within your Java applications.
Aspose.Words for Java supports DOC, OOXML, RTF, HTML and OpenDocument formats. With Aspose.Words you can generate, modify, and convert documents without using Microsoft Word.
I've used Aspose.Words to do mail merge in .NET. I believe that they also have a Java version.
You can use a Java COM bridge like JACOB. If it is from client side, another option would be to use Javascript.
There's a tool called JODConverter which hooks into open office to expose it's file format converters, there's versions available as a webapp (sits in tomcat) which you post to and a command line tool. I've been firing html at it and converting to .doc and pdf succesfully it's in a fairly big project, haven't gone live yet but I think I'm going to be using it.
http://sourceforge.net/projects/jodconverter/
docx4j or poi, both of which are ASL v2
#wondersofcomputing: iText is actually free and open source
iText is really easy to use.
If you requiere doc files you can call abiword (free lightweigh multi-os text procesor) from the command line, it has several conversion format convert options.
After a little more research, I came across iText, a PDF and RTF-file creation API. I think I can use the RTF generation to create a Doc-readable file that can then be edited using Doc and re-saved.
Anyone have any experience with iText, used in this fashion?
Bill, the POI and iText API are very similar from a programming perspective. I've worked with both in the past and found them both easy to use and well documented.
With iText you gain the advantage of being able to switch between formats (RTF and PDF) with minor change to the code. If I remember correctly the content is laid out using the same calls and then set as PDF or RTF using a few lines of code.
However I believe the formatting in RTF is limited compared to DOC. I don't know if you'll be able to implement the advanced features you are looking for (tables, inline images) without a decent amount of hassle, if at all.
Given what you said that about HWPF not having enough functionality for your needs (I've only dealt with the Excel side of POI) your best bet may be to convince the powers that be that PDF is the best technology for the job.
I have developed pure XML based word files in the past. I used .NET, but the language should not matter since it's truely XML. It was not the easiest thing to do (had a project that required it a couple years ago.) These do only work in Word 2007 or above - but all you need is Microsoft's white paper that describe what each tag does. You can accomplish all you want with the tags the same way as if you were using Word (of course a little more painful initially.)
Yet another possibility, since this is a web app.
I was able to render an HTML page with the MIME type set to "application/msword", which caused the browser to spawn Word which imported the html just fine, allowing edits and saving just as if I'd output a real Word doc.
Tables work fine, but images I hadn't gotten working yet. It may be as easy as just an tag in the HTML, or I may have to stream a separate part of the response containing the image data in binary, or some other method I haven't come up with yet. :)
Even though this is much later than the request, it might help others. Docmosis provides a Java API for creating documents in doc,pdf,odt format using documents as templates. It uses OpenOffice as the engine to perform the format conversions. Document manipulation and population is performed by Docmosis itself.
After a little more research, I came across iText, a PDF and RTF-file creation API. I think I can use the RTF generation to create a Doc-readable file that can then be edited using Doc and re-saved.
Anyone have any experience with iText, used in this fashion?