[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How do I add header text to a Rich Text Format document?

Posted on 2010-04-07
6
Medium Priority
?
4,191 Views
Last Modified: 2013-11-25
Greetings,

Background info: We have a command line program written in VB. It extracts the body of an email written in Rich Text Format (RTF) and saves it as an RTF file (The resulting file is then converted from RTF to PDF using the easyPDF library).

Problem: The RTF file currently contains the body of the email without any header information, e.g. the email sender, receiver, subject, date, attachments is missing. We want to insert this information at the very top of the RTF file so it will show at the top of the converted PDF file.

What we have already tried: We tried creating a Word object and opening the RTF file through COM. We then inserted a table as the first paragraph with the header information. The resulting RTF file looked great, but this approach is too slow (takes several seconds) and unstable (random lockups). We also tried inserting the header information directly into the RTF file stream by parsing the existing tags and adding our own table. While this was super fast, we were not able to get something to work reliably due to all the variations of the extracted RTF files. The formatting of our table was off and it sometimes caused the rest of the text to change formatting. Granted, we are not experts at the RTF format.

Question: What is a very fast and reliable/robust way to add a formatted header to an existing RTF document? We only want to add text and we always want that text to be the very first paragraph of the resulting RTF document.

Thanks!
0
Comment
Question by:karstenweber
  • 3
  • 3
6 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 30143978
I'd go with inserting the data directly into the RTF stream.  But...
Rather than adding a table (tables are known to be the most problematic of items), did you try to insert simple paragraphs of  text?
 

From: "Experts Exchange" <noreply@experts-exchange.com>\par
Sent: Thursday, April 08, 2010 11:07 AM\par
To: <danrollins@abc.net>\par
Subject: Experts Exchange - Hourly Expert Alert\par

Open in new window

0
 

Author Comment

by:karstenweber
ID: 30145429
DanRollins,

    Inserting the data directly into the RTF stream without using tables sounds like a plan. The problem then becomes how exactly to do that. The RTF is coming from Outlook so it has been through the Microsoft editor which adds a ton of formatting. I have attached a sample RTF file that starts with the words "Can you send me". As you can see over 14,000 characters of formatting as been added in front of that text. Each email appears different in terms of formatting.

    How can I parse the RTF stream to find an insertion point? (in HTML I would just look for <body> and insert my own <div> after that) I have tried inserting header information with limited success. Part of the problem was that font information for my header affected the remainder of the document. I only want to add text at the top of the document and was experimenting with adding my own {\rtf tag, but so far no luck. Any suggestions would be greatly appreciated.

Thanks!
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff31507\deff0\stshfdbch0\stshfloch31506\stshfhich31506\stshfbi31506\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f1\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604020202020204}Arial;}
{\f2\fbidi \fmodern\fcharset0\fprq1{\*\panose 02070309020205020404}Courier New;}{\f3\fbidi \froman\fcharset2\fprq2{\*\panose 05050102010706020507}Symbol;}{\f10\fbidi \fnil\fcharset2\fprq2{\*\panose 05000000000000000000}Wingdings;}
{\f34\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria Math;}{\f37\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}{\f38\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0604030504040204}Tahoma;}
{\f219\fbidi \fswiss\fcharset0\fprq2{\*\panose 020b0903020102020204}Franklin Gothic Heavy;}{\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbmajor\f31501\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhimajor\f31502\fbidi \froman\fcharset0\fprq2{\*\panose 02040503050406030204}Cambria;}
{\fbimajor\f31503\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\flominor\f31504\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}
{\fdbminor\f31505\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fhiminor\f31506\fbidi \fswiss\fcharset0\fprq2{\*\panose 020f0502020204030204}Calibri;}
{\fbiminor\f31507\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f295\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\f296\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\f298\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\f299\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\f300\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\f301\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\f302\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\f303\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\f305\fbidi \fswiss\fcharset238\fprq2 Arial CE;}{\f306\fbidi \fswiss\fcharset204\fprq2 Arial Cyr;}
{\f308\fbidi \fswiss\fcharset161\fprq2 Arial Greek;}{\f309\fbidi \fswiss\fcharset162\fprq2 Arial Tur;}{\f310\fbidi \fswiss\fcharset177\fprq2 Arial (Hebrew);}{\f311\fbidi \fswiss\fcharset178\fprq2 Arial (Arabic);}
{\f312\fbidi \fswiss\fcharset186\fprq2 Arial Baltic;}{\f313\fbidi \fswiss\fcharset163\fprq2 Arial (Vietnamese);}{\f315\fbidi \fmodern\fcharset238\fprq1 Courier New CE;}{\f316\fbidi \fmodern\fcharset204\fprq1 Courier New Cyr;}
{\f318\fbidi \fmodern\fcharset161\fprq1 Courier New Greek;}{\f319\fbidi \fmodern\fcharset162\fprq1 Courier New Tur;}{\f320\fbidi \fmodern\fcharset177\fprq1 Courier New (Hebrew);}{\f321\fbidi \fmodern\fcharset178\fprq1 Courier New (Arabic);}
{\f322\fbidi \fmodern\fcharset186\fprq1 Courier New Baltic;}{\f323\fbidi \fmodern\fcharset163\fprq1 Courier New (Vietnamese);}{\f635\fbidi \froman\fcharset238\fprq2 Cambria Math CE;}{\f636\fbidi \froman\fcharset204\fprq2 Cambria Math Cyr;}
{\f638\fbidi \froman\fcharset161\fprq2 Cambria Math Greek;}{\f639\fbidi \froman\fcharset162\fprq2 Cambria Math Tur;}{\f642\fbidi \froman\fcharset186\fprq2 Cambria Math Baltic;}{\f643\fbidi \froman\fcharset163\fprq2 Cambria Math (Vietnamese);}
{\f665\fbidi \fswiss\fcharset238\fprq2 Calibri CE;}{\f666\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;}{\f668\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\f669\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;}
{\f672\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;}{\f673\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);}{\f675\fbidi \fswiss\fcharset238\fprq2 Tahoma CE;}{\f676\fbidi \fswiss\fcharset204\fprq2 Tahoma Cyr;}
{\f678\fbidi \fswiss\fcharset161\fprq2 Tahoma Greek;}{\f679\fbidi \fswiss\fcharset162\fprq2 Tahoma Tur;}{\f680\fbidi \fswiss\fcharset177\fprq2 Tahoma (Hebrew);}{\f681\fbidi \fswiss\fcharset178\fprq2 Tahoma (Arabic);}
{\f682\fbidi \fswiss\fcharset186\fprq2 Tahoma Baltic;}{\f683\fbidi \fswiss\fcharset163\fprq2 Tahoma (Vietnamese);}{\f684\fbidi \fswiss\fcharset222\fprq2 Tahoma (Thai);}{\f2485\fbidi \fswiss\fcharset238\fprq2 Franklin Gothic Heavy CE;}
{\f2486\fbidi \fswiss\fcharset204\fprq2 Franklin Gothic Heavy Cyr;}{\f2488\fbidi \fswiss\fcharset161\fprq2 Franklin Gothic Heavy Greek;}{\f2489\fbidi \fswiss\fcharset162\fprq2 Franklin Gothic Heavy Tur;}
{\f2492\fbidi \fswiss\fcharset186\fprq2 Franklin Gothic Heavy Baltic;}{\flomajor\f31508\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\flomajor\f31509\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\flomajor\f31511\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\flomajor\f31512\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\flomajor\f31513\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\flomajor\f31514\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\flomajor\f31515\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\flomajor\f31516\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}
{\fdbmajor\f31518\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fdbmajor\f31519\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fdbmajor\f31521\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}
{\fdbmajor\f31522\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fdbmajor\f31523\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fdbmajor\f31524\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\fdbmajor\f31525\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fdbmajor\f31526\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fhimajor\f31528\fbidi \froman\fcharset238\fprq2 Cambria CE;}
{\fhimajor\f31529\fbidi \froman\fcharset204\fprq2 Cambria Cyr;}{\fhimajor\f31531\fbidi \froman\fcharset161\fprq2 Cambria Greek;}{\fhimajor\f31532\fbidi \froman\fcharset162\fprq2 Cambria Tur;}
{\fhimajor\f31535\fbidi \froman\fcharset186\fprq2 Cambria Baltic;}{\fhimajor\f31536\fbidi \froman\fcharset163\fprq2 Cambria (Vietnamese);}{\fbimajor\f31538\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}
{\fbimajor\f31539\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fbimajor\f31541\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbimajor\f31542\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}
{\fbimajor\f31543\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fbimajor\f31544\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbimajor\f31545\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}
{\fbimajor\f31546\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\flominor\f31548\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\flominor\f31549\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}
{\flominor\f31551\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\flominor\f31552\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\flominor\f31553\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}
{\flominor\f31554\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\flominor\f31555\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\flominor\f31556\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}
{\fdbminor\f31558\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}{\fdbminor\f31559\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fdbminor\f31561\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}
{\fdbminor\f31562\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}{\fdbminor\f31563\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fdbminor\f31564\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}
{\fdbminor\f31565\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}{\fdbminor\f31566\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}{\fhiminor\f31568\fbidi \fswiss\fcharset238\fprq2 Calibri CE;}
{\fhiminor\f31569\fbidi \fswiss\fcharset204\fprq2 Calibri Cyr;}{\fhiminor\f31571\fbidi \fswiss\fcharset161\fprq2 Calibri Greek;}{\fhiminor\f31572\fbidi \fswiss\fcharset162\fprq2 Calibri Tur;}
{\fhiminor\f31575\fbidi \fswiss\fcharset186\fprq2 Calibri Baltic;}{\fhiminor\f31576\fbidi \fswiss\fcharset163\fprq2 Calibri (Vietnamese);}{\fbiminor\f31578\fbidi \froman\fcharset238\fprq2 Times New Roman CE;}
{\fbiminor\f31579\fbidi \froman\fcharset204\fprq2 Times New Roman Cyr;}{\fbiminor\f31581\fbidi \froman\fcharset161\fprq2 Times New Roman Greek;}{\fbiminor\f31582\fbidi \froman\fcharset162\fprq2 Times New Roman Tur;}
{\fbiminor\f31583\fbidi \froman\fcharset177\fprq2 Times New Roman (Hebrew);}{\fbiminor\f31584\fbidi \froman\fcharset178\fprq2 Times New Roman (Arabic);}{\fbiminor\f31585\fbidi \froman\fcharset186\fprq2 Times New Roman Baltic;}
{\fbiminor\f31586\fbidi \froman\fcharset163\fprq2 Times New Roman (Vietnamese);}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;
\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;\red31\green73\blue125;\red0\green51\blue204;
\red181\green196\blue223;}{\*\defchp \f31506\fs22 }{\*\defpap \ql \li0\ri0\sa200\sl276\slmult1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 }\noqfpromote {\stylesheet{\ql \li0\ri0\sa200\sl276\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext0 \sqformat \spriority0 \styrsid1196703 Normal;}{\*\cs10 
\additive \ssemihidden \sunhideused \spriority1 Default Paragraph Font;}{\*
\ts11\tsrowd\trftsWidthB3\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblind0\tblindtype3\tscellwidthfts0\tsvertalt\tsbrdrt\tsbrdrl\tsbrdrb\tsbrdrr\tsbrdrdgl\tsbrdrdgr\tsbrdrh\tsbrdrv \ql \li0\ri0\sa200\sl276\slmult1
\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 \af31506\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \snext11 \ssemihidden \sunhideused \sqformat Normal Table;}{\*\cs15 
\additive \rtlch\fcs1 \af0 \ltrch\fcs0 \ul\cf2 \sbasedon10 \ssemihidden \sunhideused \styrsid8804812 Hyperlink;}{\s16\ql \li0\ri0\sb100\sa100\sbauto1\saauto1\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0 \rtlch\fcs1 
\af0\afs24\alang1025 \ltrch\fcs0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext16 \ssemihidden \sunhideused \styrsid8804812 Normal (Web);}{
\s17\ql \li720\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin720\itap0 \rtlch\fcs1 \af0\afs24\alang1025 \ltrch\fcs0 \fs24\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 \sbasedon0 \snext17 \sqformat \spriority34 \styrsid8804812 
List Paragraph;}}{\*\pgptbl {\pgp\ipgp21\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp2\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp19\itap0\li0\ri0\sb0\sa0\brdrt
\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp3\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li720\ri720\sb100\sa100}{\pgp\ipgp20\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }
{\pgp\ipgp29\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp12\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp
\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp0\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp27\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp7
\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp13\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp1\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp25
\itap0\li0\ri0\sb0\sa0\brdrt\brdrs\brdrw20\brsp60\brdrcf19 }{\pgp\ipgp8\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}{\pgp\ipgp16\itap0\li0\ri0\sb0\sa0}}{\*\rsidtbl \rsid1196703\rsid4397744\rsid8804812\rsid13126439\rsid14037871}{\mmathPr
\mmathFont34\mbrkBin0\mbrkBinSub0\msmallFrac0\mdispDef1\mlMargin0\mrMargin0\mdefJc1\mwrapIndent1440\mintLim0\mnaryLim1}{\info{\author Karsten S Weber}{\operator Karsten S Weber}{\creatim\yr2010\mo4\dy8\hr12\min27}{\revtim\yr2010\mo4\dy8\hr12\min29}
{\version3}{\edmins0}{\nofpages8}{\nofwords1674}{\nofchars11020}{\nofcharsws12669}{\vern32771}}{\*\xmlnstbl {\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\gutter0\ltrsect 
\widowctrl\ftnbj\aenddoc\trackmoves1\trackformatting1\donotembedsysfont1\relyonvml0\donotembedlingdata0\grfdocevents0\validatexml1\showplaceholdtext0\ignoremixedcontent0\saveinvalidxml0\showxmlerrors1\noxlattoyen
\expshrtn\noultrlspc\dntblnsbdb\nospaceforul\formshade\horzdoc\dgmargin\dghspace180\dgvspace180\dghorigin1440\dgvorigin1440\dghshow1\dgvshow1
\jexpand\viewkind1\viewscale100\pgbrdrhead\pgbrdrfoot\splytwnine\ftnlytwnine\htmautsp\nolnhtadjtbl\useltbaln\alntblind\lytcalctblwd\lyttblrtgr\lnbrkrule\nobrkwrptbl\snaptogridincell\allowfieldendsel\wrppunct
\asianbrkrule\rsidroot8804812\newtblstyruls\nogrowautofit\usenormstyforlist\noindnmbrts\felnbrelev\nocxsptable\indrlsweleven\noafcnsttbl\afelev\utinl\hwelev\spltpgpar\notcvasp\notbrkcnstfrctbl\notvatxbx\krnprsnet\cachedcolbal \nouicompat \fet0
{\*\wgrffmtfilter 2450}\nofeaturethrottle1\ilfomacatclnup0\ltrpar \sectd \ltrsect\linex0\endnhere\sectlinegrid360\sectdefaultcl\sectrsid1196703\sftnbj {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl2
\pnucltr\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang {\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang {\pntxta )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl6
\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang 
{\pntxtb (}{\pntxta )}}\pard\plain \ltrpar\ql \li0\ri0\widctlpar\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\itap0\pararsid8804812 \rtlch\fcs1 \af31507\afs22\alang1025 \ltrch\fcs0 
\f31506\fs22\lang1033\langfe1033\cgrid\langnp1033\langfenp1033 {\rtlch\fcs1 \af37 \ltrch\fcs0 \f37\cf17\insrsid8804812\charrsid8804812 Can you send me 

Open in new window

Sample-RTF-code.txt
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 30147868
What I've done in the past is start with a "base" RTF file in which I have provided a uniquely-recognizable sequence of text, maybe something like:
    $*$MailHeaderLinesGoHere$*$
Then replace that string with the stuff I need to insert.
If that is an option, you could even create an empty table, with a series of "unique replacement terms" like $*$NameGoesHere$*$ as placeholders within the table.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:karstenweber
ID: 30150401
I see exactly what you mean. This will give me a valid RTF strings to be inserted into the RTF file. However, the problem is that I do not control the "base" RTF file. It is generated in an email editor on someone elses computer (think of it as a random RTF file). The example that I attached earlier show over 14,000 characters of formatting between the initial RTF tag and the first line of actual text.

The question is: How do I know where within those 14,000 characters of formatting, that I can safely insert my own header text?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 2000 total points
ID: 30171930
Alas.
Is there nothing that you can find that is similar among the various RTF files?  Some standard text that all have?
It might not be as hard as it looks to find the first non-control sequence.  Match opening and closing brackets {...}  THen I think that all RTF tokens start with \ and end with a space.  If you ever get to a non-token, then you are at visible text.
Another option that's closer to what you tried with Ms Word:
Instantiate a RichText ActiveX control and feed the original RTF into it.  Then you can programmatically insert text at the top -- all without invoking Ms Word.  I could do this in C++ pretty quickly, but I have no experience doing that sort of thing in VB.
0
 

Author Closing Comment

by:karstenweber
ID: 31712148
Thanks DanRollins for all the help.
This might be easier than I originally thought. All RTF files starts with {\rtf. For example {\rtf1\ansi\deff0 where each \ is the beginning of a control character. Turns out that it is valid to break the stream after the first rtf control character. In the above example I can do the following:

{\rtf1 ' Break after the first rtf control
Some Example Text\par ' Insert my own text and formatting here
\ansi\deff0  ' Continue the original stream
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Why WooCommerce is one of the majorly favored choices when it comes to having an eCommerce store. This article will acquaint you with some reasons that I believe make it one of the best eCommerce platforms available.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Loops Section Overview

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question