We help IT Professionals succeed at work.

Inserting an RTF into an RTF Dynamically

sulzener
sulzener used Ask the Experts™
on
I am trying to insert an RTF into an exiting RTF via ColdFusion with this code:

<cfset NewRTF = Replace(NewRTF, "@@NEWRTFNAME@@","#New_RTF_Name#","ALL")>

The Main RTF is layed out like

1.1 Header
1.2 Header
2.1 Header
2.2 @@VARIABLENAME@@
3.1 Header

 So I When I insert the RTF into the Original RTF, it looks like this:

1.1 Header
1.2 Header
2.1 Header
 · Inserted RTF Header Name
2.2
3.1 Header

So instead of putting in after the 2.2 , it puts it above it.
Now if I get it to replace the variable and put after the 2.2 it screws up the number below it. Like the 3.1 would come 3.3.

So I was wondering if you anyone has ever done anything like this and if they could hive me a few tips or tell me what I am doing wrong?

Or if anyone has  a link to a good reference?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Have you tried removing the - character from the variable name? Although I am not that familiar with RTF format I would guess that the - is messing up the layout and would need to be escaped somehow.

Let me know if this doesn't fix it and I will look into it for you.

Author

Commented:
Yes, I tried removing the _ character  and it still does not work. It is actually a ColdFusion variable being put into a RTF variable. But even removing that character. It is more in the RTF Code, cause if I change the rtf code, it will move and put the new text in different places in the RTF. So I still have not gotten anywhere.
Can you please attach the RTF file that you are working with or just the section that has the problem, before you make the substitution. And can you include a bit more of the CF code where you read and save the file.


Also what exactly is the value in #New_RTF_Name# ?

Author

Commented:
Thanks StaticVortex - Here is the CF Code for reading and replacing. Then I do a cfmail and email it to myself.

Experts Exchange would not allow me to upload RTFs, so I changed the File Extensions to TXT. You can change the extensions to RTF and then open in word and then open in word pad to see the RTF Code.

The Main_RTF is the main template and where the @@RTFVARIABLE@@ is, is where the Insert_RTF should be inserted.

It should not mess up number systems or anything like that. Let me know if you need anything else more, more CF Code, More explanation or anything else like that. Thank you

<cfset MainRTFPath  = fullpath & "Main_RTF.rtf">

<cfset InsertRTFPath  = fullpath & "Insert_RTF.rtf">	

<cffile action = "read" 
file = "#MainRTFPath#" 
variable = "NewRTF">

<cffile action = "read" 
file = "#InsertRTFPath#" 
variable = "InsertRTF_Variable">	

<cfset NewRTF = Replace(NewRTF, "@@RTFVARIABLE@@","#InsertRTF_Variable#","ALL")>

Open in new window

Main-RTF.txt
Insert-RTF.txt
I thought you were just inserting some text. Didn't realise you were trying to insert another whole RTF file? Is that what you are trying to do? If that is the case then it is potentially a lot more complicated?

Author

Commented:
Yes, I am trying to insert a whole RTF file into an RTF, Not just text. I have the text portion working correctly, it is the RTF into the RTF that I can not get to work. Thank you
Well you would need to strip all the headers and footers from the inserting RTF file which could be pretty unreliable, unless you know the exact format of RTF files.

There maybe a parser out there that could turn the RTF into some other type of structure like an XML document that would then be easier to work with.

Let me know if you would like me to help find you some sort parser / conversion library that could help?

Author

Commented:
Yes, if you would have any suggestions on some sort of parser / conversion library. I have looked myself, but to no avail. I am still in the same boat. Thanks for your time and help.

Author

Commented:
I stripped all the header, footer, themes and extra RTF code that was not needed from the second RTF and got it working.

Author

Commented:
I stripped all the header, footer, themes, and extra RTF code from the RTF that will be inserted and it is working now. Thanks for the help

Author

Commented:
I also saved them as txt files instead of rtf.