PDA

View Full Version : Insert RTF into existing document


Unregistered
October 16, 2002, 00:02:55
Hi.

Here's my situation. I've got a TextControl with an rtf file open in the control. I'd like to insert an rtf string into that document.

The catch is the rtf header on the rtf string. I don't have one. I just have the body of the rtf.

Any suggestions on how I can load that rtf string? Is there a way I can grab the header of the open rtf file, add it to the rtf string, and load that?

Ideas? Suggestions?

Elizabeth


This message was originally posted by Elizabeth in the old TX Text Control Support Forum.

Unregistered
October 16, 2002, 02:19:05
You can create a simple file in WordPad then open it with Notepad to get a dummy header. Copy it once into your program as a string to add to your own text, something like

RtfHeader = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\fswiss\fcharset0 Arial;}}"

MyRtfBuffer = RtfHeader + MyRtfText + "}"

---Dave


This message was originally posted by Dave Simmons in the old TX Text Control Support Forum.

Unregistered
October 16, 2002, 07:44:24
You can save the current doc to memory / string and try to find the end of the header manually but that can be tricky.

Or a brute force approach:
- Insert a marker string at the insertion point, for example "-=$=mark=$=-"
- save the doc to memory
- split the doc string into before-the-mark and after-the-mark
- combine before + new-text + after
- replace the entire document

Hopefully someone else can suggest something more elegant :-)

---Dave


This message was originally posted by Dave Simmons in the old TX Text Control Support Forum.

Unregistered
October 16, 2002, 15:51:49
Thanks Dave -- I'm going to give it a try . . .

One question -- how would I do this part:

- split the doc string into before-the-mark and after-the-mark

while the doc is in memory?

Thanks . . .

Elizabeth


This message was originally posted by Elizabeth in the old TX Text Control Support Forum.

Unregistered
October 16, 2002, 19:09:35
> how would I do this part:
> - split the doc string into before-the-mark and after-the-mark

Depends on the language, what are you using?

In C++ strstr() to find the mark, in VB6 I forget what the function is to find the index of one string within another string. You'd split with left() and mid(). I think the VB6 online help will have some sample code under "string functions" or similar.


This message was originally posted by Dave Simmons in the old TX Text Control Support Forum.

Unregistered
October 17, 2002, 23:19:40
I'm using VB.

SaveToMemory returns a byte array, not a string. So I can't use VB's string functions.

Right now I'm trying to do it by loading the rtf document as ANSI text (format 1) into another text control . . . then insert the text into the second text control . . . then reload it as rtf into the first control.

But it aint working. I have more work to do on it however.


This message was originally posted by Elizabeth in the old TX Text Control Support Forum.

Unregistered
October 19, 2002, 14:51:50
Could you Paste the data into the existing document.


This message was originally posted by Matt in the old TX Text Control Support Forum.

Unregistered
October 28, 2002, 20:39:48
Matt --

I was able to get this to work using a hidden text control.

I put a marker string at the location where I want the rtf to be inserted (eg, !!!+marker+!!!). I save the current document to memory as an rtf file. I then load it in the hidden text control as a plain text (Format =1).

I replace the marker with the rtf bit that I want to insert. I turn this document into a byte array, and then use LoadFromMemory to reload it into the visible text control.

Hope someone finds that useful.


This message was originally posted by Elizabeth in the old TX Text Control Support Forum.