views:

1498

answers:

2

Hi,

We have some code which produces an RTF document from a RTF template. It is basically doing string search and replaces of special tags within the RTF file. This is accessible via a web page.

Typically, the processing time for this is really quick.

However, we need to embed an image within a template. We've been embedding these as JPEG images using Word's "Insert/Picture/From File..." functionality. But we've found that the resultant RTF file size is massively dependant upon the image.

For example, I've inserted a 20k JPEG logo (which is basically a solid background with some text). The RTF file increased in size from around 390k (without the image) to 510k (with the image).

Then we inserted a JPEG containing a screenshot, i.e. the image contains text, multiple colours, etc. The JPEG is around 150k. Using this image, the RTF file increased in size from 390k to 3.5MB.

So the encoding that Word uses for storing images into an RTF doesn't perform linearly. I'm guessing it is dependant upon what is in the JPEG image.

I need to keep the size of the RTF templates to a minimum to try and keep our file processing times to a minimum.

  • Does anyone have any ideas on how to minimize the size of the RTF files with embedded images?
  • Is there any way of controlling the encoding that Word uses? I can't see any options anywhere.
  • Does anyone know what type of binary encoding Word/RTF uses?

Thanks in advance.

+1  A: 

An image in an RTF file gets stored as a WMF, uncompressed. On mac, it it would be macpict. Your best bet to keep the file size down is to link the image to the document rather than insert a copy in the document. The trade-off is that you have to keep the files together.

EDIT Is compressing the RTF an option? Using zip/rar, you'll get your file size back, but you'll have to uncompress, first obviously. There are supposed to be tools that will do rtf compression, but I have never used them.

DaveParillo
Thanks. Zipping wouldn't help - I'd still need to unzip to process the file. It's not the file storage size that's my problem - it's the time taken to process the RTF.I don't understand about the linking - I'm probably lacking in Word skills... is it possible to get Word to hyperlink to a URL and display the contents of that URL in the document? I can easily make my images available via a URL. As long as the image appears in the document to the reader and the reader doesn't have to do anything to get the image, then I'd be happy (i.e. I don't want my users to have to click a link)
A_M
Adding a hyperlink is easy either from within word itself or VBA, but sorry I don't know how to have the image be visible inside the rtf doc, but not have a copy of the WMF inside. Screen shots tend to be far larger than they need to be if you have non-white backgrounds, for example. You might consider editing your images and saving them as bmp's. The bmp format will give you an idea of how big the wmf will be. How much color information do you lose saving as a 16 bit image?
DaveParillo
DaveParillo
Thanks for the suggestion - I'll give this a try.
A_M
+1  A: 

Here is the best solution

http://support.microsoft.com/kb/224663

swartbees