views:

275

answers:

1

Hi all,

I've seen people speaking about that on the web, I've been advised to do that, but it looks like the iText rendering engine is far from matching MS word (openoffice, TeX). And interpreting a .doc is far from trivial anyway (J.Spolsky explained why) so I'm a little bit of skeptical.

I'd really like to do that for a project, but I can't find anything on the net, I think the simplest way would be modularising openoffice and grabbing the input system, the layout system and the output system, leaving the UI on the bank. But the closest thing I see on the net right now is connecting to a live instance of OpenOffice/MS Office and sending commands (read .doc, generate PDF) to it.

Do you have any code on the web to show this [read .doc -> edit a little bit in the document (add a small table, fill blanks) -> generate PDF] mythical chain ?

thanks, Nico.

+1  A: 

I would surmise that this is really only hypothetically possible. That is, it sounds as though the software in question should do it, but the reality is far different. As you rightly state DOC and PDF are very different formats, and the only way of creating a faithful one-to-one translation of a DOC as a PDF would be to print it and capture the output, much as the many PDF creators do.

POI, and other software such as Aspose.Words will let you read the structure of a DOC, and iText will let you create a PDF, but there's bound to be a million little foibles and edge-cases in both that means any implementation of a converter is sure to be non-trivial. Off the top of my head I can tell you that iText has poor support for splitting rows in tables. On a project I worked on we had to render row-split table cells as a kind of "off-screen PDF image", and then embed the image in a single table cell. A pleasant enough hack in the end, but you'd be very hard-pressed to reproduce some of the richer features that DOC supports before you even start to think about embedded OLE objects, ActiveX controls, AutoShapes, right-to-left languages, etc. And let's not forget that every version of Word introduces new features to DOC and fixes things things that are wrong in older ones.

For simple enough documents you might be able to achieve a reasonable result for a little effort. I've never done it, and I wouldn't really want to try because I know that results would be mediocre once the complexity of the source document rises beyond paragraphs and headers. Whatever it is you're trying to do I'd encourage you to look for another way first.

banjollity