• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Coverting RTF to DOC

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i convert an rtf document to ms word document using java api.Please suggest
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your best bet may be the OpenOffice Java API; see http://faq.javaranch.com/java/AccessingFileFormats for some links.

Why do you want to convert the document? Word can open RTF files just fine.
 
Subha Garg
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]

now time is=[time to generate big report file]+[time to read big report file into zipped file]+[download time of unipped file] .
[ March 04, 2008: Message edited by: Subha Garg ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is still taking long time to generate report


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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

//creating myfile.rtf to disk which consist of[a merged file with images] +[file generated throgh iText's RtfWriter2]

//Reading myrtf,zipping it and sending to browser.

FileInputStream fin = new FileInputStream("myfile.rtf");
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment;filename=\""+ "FullElementReport"+ ".zip\";");
ZipOutputStream zout = new ZipOutputStream(response.getOutputStream());
zout.putNextEntry(new ZipEntry("FullElementReport.rtf"));

int len = 0;
byte arr [] = new byte[1024];
while((len=fin.read(arr))> 0)
{
zout.write(arr,0,len);
}
zout.closeEntry();
fin.close();
zout.flush();
zout.close();

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 ]
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79984
398
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Naga Varadharaju

Unfortunately this is an old thread (see this FAQ with a corny name) so you might not get a reply from the previous posters/
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic