Why do you want to convert the document? Word can open RTF files just fine.

Subha Garg

Ranch Hand

Posts: 39

posted 9 years ago

I am creating rtf reports using iText.jar's RtfWriter.As a result i get my report in rtf format.But Rtf file generated is huge in size compared to its' word format.And it takes a lot of time to send an rtf file from servlet to browser due to its huge size.if i can somehow able to convert it to word which shrinks the size even less than than the zipped format of rtf.than tranfering from servlet to browser would take less time.

Ulf Dittmer

Rancher

Posts: 42972

73

posted 9 years ago

If this were my problem I'd look into why the file is so big to begin with - does it define styles that aren't used? Images? Does iText embed fonts? (Fonts would make the file big in a hurry. Actually, I'm not sure if you can embed fonts in RTF; but iText can do it for PDFs.)

Also, since RTF is just text (as opposed to DOC, which is binary), using the web server's gzip compression should help, too.

Subha Garg

Ranch Hand

Posts: 39

posted 9 years ago

Although i have temporarily managed by converting the rtf file to zip and send the zipped file to browser but i still need the rtf file to be converted to doc file through java api or require a tool which allows creation of word reports.

it is still taking long time to generate report

earlier i was creating [big rtf file] using iText.jar and writing its contents to response.getOutputStream() from the memory

now i am creating [big rtf file] to hard disk+reading [big rtf file] from hardisk adding it to zip file and writing zip file to response.getOutputStream()

earlier

total time was = [time to generate big report file]+[download time of unzipped file]

If that is the problem, generating DOC instead of RTF likely isn't going to make a difference. I'd look into why it is taking a long time, and try to find ways of speeding it up.

Subha Garg

Ranch Hand

Posts: 39

posted 9 years ago

Downloading doc surely makes a huge difference as i have tested it.Size of generated rtf file + merged file which contains images etc is as big as 20 MB but size of same rtf when converted to doc by manually opening it in MS-Word and changing its format while saving it throgh saveAs to doc reduces it to tiny 500 kbs.So i think changing rtf to doc would make a big difference.

Ulf Dittmer

Rancher

Posts: 42972

73

posted 9 years ago

Ah, this is the first time you mention that those files contain images. Yes, those are ASCII-encoded in RTF, which makes them much bigger than embedding them in binary form (which is what DOC does).

But you said that generating the report takes a long time, and using RTF vs. DOC shouldn't have as much impact on that. Just another thing you could look into if you want to speed up the whole process. [ March 05, 2008: Message edited by: Ulf Dittmer ]

Subha Garg

Ranch Hand

Posts: 39

posted 9 years ago

i think zipping does solve the size problem but it has also added a performance overhead.if i write rtf directly on response.getOutputStream() the in memory copy of file is wriiten to the output stream.now i am creating a file on th disk.reading it into zip file as follows

what possible optimization can i make here?how many maximum bytes can i read frmo the file at a time? [ March 05, 2008: Message edited by: Subha Garg ]

Naveen K Garg

Ranch Hand

Posts: 105

posted 9 years ago

Hi Subha,

You have take a look at Jakarta POI api for generating word document.

It might help you.

Using iText for creating simple rtf is ok but it is not suitable for big word document as it is mainly used to generate the PDF files.

Hope this will help

- Naveen Garg

Subha Garg

Ranch Hand

Posts: 39

posted 9 years ago

But i have heard Apache POI is mainly for excel format.Also i could not find very good tutorial a nd help files for apache POI HWPF?Does it allow creation of word reports.I want to create word files containg tables.I should be able to create table of contents automatically.I also want to insert header's and footers of my choice as supported by ms-word.I also want to add contents of the font of my choice.Is that all possible with POI HWPF?if yes?can you send me link to site having examples on it other than the home site.I couldnt find anything on that junit examples.

Ulf Dittmer

Rancher

Posts: 42972

73

posted 9 years ago

The POI DOC functionality is quite basic. It won't suffice for what you describe.

The OpenOffice Java API on the other hand can generate any kind of DOC file, but it has a steep learning curve. (Which is to be expected, really, given everything that OO can do.) [ March 05, 2008: Message edited by: Ulf Dittmer ]

Naveen K Garg

Ranch Hand

Posts: 105

posted 9 years ago

I agree with Ulf. The support for MS Word in Apache POI is very basic.

Considering your requirements you might want to go for a commercial Java API.

- Naveen Garg

Naga Varadharaju

Greenhorn

Posts: 6

posted 8 years ago

Subha,

Do you have the code with you for merging RTF and Word Document. I'm trying to do this with Apache POI api. But if you can share it with me it would be great. Also did you implement ZIP format? Thanks, Naga