How do I add header text to a Rich Text Format document?
Posted on 2010-04-07
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.