Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merging several RTF blocks together

Status
Not open for further replies.

Guggly

Programmer
Jan 18, 2004
110
US
Hi! I'm not sure which is the best forum to post this kind of question, so if you have any suggestions as to a different forum, do tell :).

I have a table which contains several thousand individual blocks of RTF text (some of which contain graphics, and if you've ever attempted to store a graphic in RTF you'll know that that makes the files HUGE). I need to somehow programatically merge these blocks into a number of RTF files, one file might have 100 or so blocks of text, for instance.

The problem is, you can't just take the raw RTF text (i.e. the underlying text, not the formatted result) and combine multiple blocks in the same file. Right now what I'm doing is using the Microsoft RTF Control to read the text and then copy it into another text box where it's all combined and saved to file. But this method is very slow and seems to be buggy.

Short of doing something like writing the text to a file and automating Microsoft Word to open and merge the data (which would be horrendously slow) are there any other thoughts on how to do this?

Is there any simple way to parse the RTF so that I can combine the data?

Thanks in advance -- Mike
 
Hi Mike,

You can easily link multiple 'source' rtf blocks together in a 'target' file, regardless of whether the 'source' rtf blocks are in one file or multiple files, using Word's INCLUDETEXT fields.

If you want to link to the content of two complete rtf files, you'd use a pair of INCLUDETEXT fields coded like:
{INCLUDETEXT "C:\\My Path\\Source1.rtf"}
and
{INCLUDETEXT "C:\\My Path\\Source2.rtf"}

If you only want part of a given file, or multiple parts from the same file, all you need to do is to bookmark each of those parts and code the fields like:
{INCLUDETEXT "C:\\My Path\\Source1.rtf" BkMrk1}
and
{INCLUDETEXT "C:\\My Path\\Source1.rtf" BkMrk2}
where BkMrk1 and BkMrk2 are the bookmark names.

The technique works equally well with text, tables and graphics. The only significant issues to watch out for are:
1. Paragraph styles that exist in both the source and target documents take on the style formatting that's applied in the target document; and
2. If you move the source documents to another folder, the links will break.

Cheers
 
Thanks macropod, that could be an interesting solution. I'm hoping not to have to write each of the RTF records to a file, since there are several thousand of these. I guess I'll see what my options are!
 
He is not suggesting you write each RTF to a file. He is suggesting you identify each block as being a bookmark, and then use THOSE with INCLUDETEXT.

The question becomes - how are you getting the RTF blocks? If they are discretely entered into the document, by code, then each entry of RTF can easily be made into a bookmark during the process. Voila! You can use INCLUDETEXT with bookmarks.

The problem is, you can't just take the raw RTF text (i.e. the underlying text, not the formatted result) and combine multiple blocks in the same file.
Yes you can.

So how are the RTF put together in the first place?

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top