RTF format

nsdlsandy
nsdlsandy used Ask the Experts™
on
I have a text stored in database as

{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\fnil\\fcharset0 Courier New;}{\\f1\\fnil\\fcharset2 WingDings;}}{\\colortbl\\red0\\green0\\blue0;\\red255\\green0\\blue0;\\red0\\green128\\blue0;\\red0\\green0\\blue255;\\red255\\green255\\blue0;\\red255\\green0\\blue255;\\red128\\green0\\blue128;\\red128\\green0\\blue0;\\red0\\green255\\blue0;\\red0\\green255\\blue255;\\red0\\green128\\blue128;\\red0\\green0\\blue128;\\red255\\green255\\blue255;\\red192\\green192\\blue192;\\red128\\green128\\blue128;\\red0\\green0\\blue0;}\\wpprheadfoot1\\paperw15840\\paperh12240\\margl2500\\margr2500\\margt1440\\margb1440\\margh720\\margf720{\\*\\listtable{\\list\\listtemplateid19690212{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc1{\\leveltext\\'02\\'00.;}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc3{\\leveltext\\'02\\'01.;}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\
\levelindent360\\levelnfc0{\\leveltext\\'02\\'02.;}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc4{\\leveltext\\'02\\'03);}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc2{\\leveltext\\'02\\'04);}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc4{\\leveltext\\'02\\'05);}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc0{\\leveltext\\'02\\'06);}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc0{\\leveltext\\'02\\'07);}{\\levelnumbers\\'01;}}\n{\\listlevel\\leveljc0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent360\\levelnfc0{\\leveltext\\'02\\'08);}{\\levelnumbers\\'01;}}\n\\listid1194737}}{\\*\\listoverridetable{\\listoverride\\listid1194737\\listoverridecount0\\ls1}}\\endn
here\\sectdefaultcl{\\pard{\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 THIS REVIEW.\\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 PAGE 00\\tab \\plain\\f0\\fs20\\cf0\\b CERT-LABEL FD\\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\tab \\tab \\tab PADED 'DEL-FLAG        1 AN'\\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\tab \\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 PAGE 000\\tab LINE 02 CHANGED 'PR' TO 'RT'\\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\tab \\tab \\tab 04 'INFO-SM' TO \\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\tab \\tab \\tab \\tab \\tab     'COMP-IY
BL-DESC-TX'\\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\tab \\tab \\tab TL 05 MDT 'NEWS'\\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 \\par\n\\ql\\li0\\fi0\\ri0\\sb0\\sl\\sa0 \\plain\\f0\\fs20\\cf0 IE 00S-00M\\tab JAMBA JUICE FROM 'SMSMSMS' TO 'IYIY'}}\n}


I tried using various editors (FreeTextBox, Telerik .. etc.) to open this data.
I can see the text but I loose the formatting. I tried to save data as Temp.rtf and open with Word but it doesn't recognize this RTF syntax.
Alternately, When I save a Word document as RTF  .. I see the syntax of that RTF is different from the RTF I have.

Can you please help me with the RTF I have to not only open the data but also see the Format.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Richard QuadlingSenior Software Developer

Commented:
Search/replace \\ with \

The \ is escaped.

Unescaping the \ results in ...

a.doc
try using this class (I had a similar requirement.

I makes use of Win word Com. Im not sure its exacly what you want - but you should be well on your way with it.
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.Collections.Generic;
using Application = Microsoft.Office.Interop.Word.Application;
using Encoder=System.Drawing.Imaging.Encoder;


namespace ReportingWebInterface
{    
    public class RtfConverterClass :IDisposable
    {
        protected Application _WinWordInstance;

        private object _Missing = Type.Missing;
        private object _oFalse = false;
        private List<string> _TempFiles ;

        private object _LockThis = new object();

        private string TempDirectory
        {
            get
            {
                var tempdir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Temp\\";

                if (!Directory.Exists(tempdir))
                    Directory.CreateDirectory(tempdir);

                return tempdir;
            }
        }
        
        public RtfConverterClass()
        {
            _TempFiles = new List<string>();

            try
            {
                //Windows bug : Winword interop will not work correctly with: ASP.NET | FRAMEWORK 2 | Serv2008 | office 2007 
                //unless this dir exists and unfortunatly it does not exists by default
                //http://social.msdn.microsoft.com/forums/en-US/architecturegeneral/thread/0f5448a7-72ed-4f16-8b87-922b71892e07/

                // please remember to run iis app pool with an admin account to get access to the temp folders
                //P.S dont forget to configure DCOM config for word interop

                var desktop = @"C:\Windows\SysWOW64\config\systemprofile\Desktop\";

                if (!Directory.Exists(desktop))
                    Directory.CreateDirectory(desktop);

            }
            catch (Exception)
            {
                //eat it
            }
        }

        ~RtfConverterClass()
        {
            Dispose();
        }
                
        private Application GetWinWordComObject()
        {
            if (_WinWordInstance == null)
            {
                _WinWordInstance = new Application {Visible = false};
            }
            return _WinWordInstance;     
        }

        private string ToRtf(string rtfData, string rtfFileName)
        {
            if (rtfFileName == null)
            {
                rtfFileName = TempDirectory + Guid.NewGuid() + ".rtf";
            }

            if (File.Exists(rtfFileName))
                File.Delete(rtfFileName);

            using (var rtfTempFile = new FileStream(rtfFileName, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                var bytes = Encoding.ASCII.GetBytes(rtfData);
                rtfTempFile.Write(bytes, 0, bytes.Length);
                rtfTempFile.Close();
            }
            return File.Exists(rtfFileName) ? rtfFileName : null;
        }


        public string ToFile (string rtfData, string destFileName)
        {
            switch (Path.GetExtension(destFileName).ToLower())
            {
                case ".rtf":
                    return ToRtf(rtfData, destFileName);
                case ".html":
                case ".htm":
                    return ToHtml(rtfData, destFileName);
                default:
                    return ToImage(rtfData, destFileName);
            }
        }

        private ICollection<string> GetImagesFromHtml(string html)
        {
            if (File.Exists(html))
            {
                using (var sr = new StreamReader(html))
                {
                    html = sr.ReadToEnd();
                    sr.Close();
                }
            }
            var list = new List<string>();
            var pattern = new Regex("(?<=<img[^<]+?src=\")[^\"]+");

            foreach (var match in pattern.Matches(html))
            {
                list.Add(match.ToString());
            }

            return list;

            
        }

        /// <summary>
        /// This function checks if the image that is already there and if the rtf used to create the image has changed.
        /// If not we wont bother recreating the image 
        /// </summary>
        /// <param name="rtfData"></param>
        /// <param name="imageFileName"></param>
        /// <returns>false means that we need to recreated the image from the rtf, true means the rtf and the image are correct already</returns>
        private bool ExistingImageIsCorrect(string rtfData, string imageFileName)
        {
            if (!File.Exists(imageFileName)) 
                return false;

            if (!File.Exists(imageFileName + ".rtf")) // we have something to compare against
                return false;
            
            string oldRtf;
            using (var fs = new FileStream(imageFileName + ".rtf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var sr = new StreamReader(fs))
                {
                    oldRtf = sr.ReadToEnd();
                    sr.Close();
                }
                fs.Close();
            }
            return oldRtf.Equals(rtfData);
        }

        private string WriteToImage (string rtfData, string imageFileName)
        {
            var dirSaveLocation = Path.GetDirectoryName(imageFileName);

            if (!Directory.Exists(dirSaveLocation))
                Directory.CreateDirectory(dirSaveLocation);

            var rtfFile = ToRtf(rtfData, imageFileName + ".rtf");
            var tempHtmlFile = ToHtml(rtfFile, null);
            TempFile(tempHtmlFile);

            foreach (var file in GetImagesFromHtml(tempHtmlFile))
            {
                // these image files are also temp files
                TempFile(Path.GetDirectoryName(tempHtmlFile) + "\\" + file);
            }

            DrawHtmlFile(tempHtmlFile, imageFileName);

            return File.Exists(imageFileName) ? imageFileName : null;
        }

        public string ToImage (string rtfData, string imageFileName)
        {
            return ExistingImageIsCorrect(rtfData, imageFileName) ? imageFileName : WriteToImage (rtfData, imageFileName);
        }

        private static ImageFormat GetImageFormat(string fileExtention)
        {
            switch (fileExtention.ToLower())
            {
                case ".bmp":
                    return ImageFormat.Bmp;
                case ".emf":
                    return ImageFormat.Emf;
                case ".exif":
                    return ImageFormat.Exif;
                case ".gif":
                    return ImageFormat.Gif;
                case ".ico":
                    return ImageFormat.Icon;
                case ".jpg":
                case ".jepg":
                    return ImageFormat.Jpeg;
                case ".mdf":
                    return ImageFormat.MemoryBmp;
                case ".png":
                    return ImageFormat.Png;
                case ".tif":
                case ".tiff":
                    return ImageFormat.Tiff;
                case ".wmf":
                    return ImageFormat.Wmf;
                default:
                    return ImageFormat.Jpeg;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="rtfData"></param>
        /// <returns>path to the created html file</returns>
        public string ToHtml(string rtfData)
        {
            return ToHtml(rtfData, null);
        }

        private void TempFile(string fileName)
        {
            if (_TempFiles == null)
                _TempFiles = new List<string>();

            if (File.Exists(fileName))
                _TempFiles.Add(fileName);
        }


        static void DrawHtmlFile(object fromUrl)
        {
            var passedin = fromUrl as object[];

            if (passedin == null || passedin.Length != 2) return;

            var tempHtmlFile    = passedin[0].ToString();
            var imageFileName   = passedin[1].ToString();

            using (var ie = new WebBrowser())
            {
                ie.Width = 690; // for A4 page - have to set here as page may have % widths

                ie.ScrollBarsEnabled = false;
                ie.ScriptErrorsSuppressed = true;
                ie.Navigate(tempHtmlFile);

                while (ie.ReadyState != WebBrowserReadyState.Complete)
                    System.Windows.Forms.Application.DoEvents();

                if (ie.Document == null || ie.Document.Body == null) return;

                ie.Height = ie.Document.Body.ScrollRectangle.Size.Height; // so we can see the entire document.
                ie.Width = ie.Document.Body.ScrollRectangle.Size.Width; // so we can see the entire document (as it was initiall created).

                using (var bitmap = new Bitmap(ie.Width, ie.Height))
                {
                    var drawRect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
                    ie.DrawToBitmap(bitmap, drawRect);
                    bitmap.Save(imageFileName, GetImageFormat(Path.GetExtension(imageFileName)));
                }
            }
        }

        public bool DrawHtmlFile(string fromUrl, string toImageFile)
        {
            var threadParam = new object[] { fromUrl, toImageFile };
            var t = new System.Threading.Thread(DrawHtmlFile);
            t.SetApartmentState(System.Threading.ApartmentState.STA);
            t.Start(threadParam);

            t.Join(); // Wait for thread to Finish before carrying on

            while (t.IsAlive)
                System.Windows.Forms.Application.DoEvents();

            return File.Exists(toImageFile);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="rtfData"></param>
        /// <param name="htmlFileName"></param>
        /// <returns>path to the created html file</returns      
        public string ToHtml(string rtfData, string htmlFileName)
        {
            if (string.IsNullOrEmpty(htmlFileName))
                htmlFileName = TempDirectory + Guid.NewGuid() + ".htm";

            string tempRtfFile;

            if (rtfData.EndsWith(".rtf", StringComparison.OrdinalIgnoreCase) && File.Exists(rtfData))
            {
                tempRtfFile = rtfData;
            }
            else
            {
                tempRtfFile = ToRtf(rtfData, null);
                TempFile(tempRtfFile);
            }
            
            //Read the Rtf File
            var doc = OpenDocument(tempRtfFile);

            if (doc == null)
                return null;

            try
            {
                object oFileName = htmlFileName;
                object oFormat = WdSaveFormat.wdFormatFilteredHTML;

                doc.WebOptions.AllowPNG = true;
                doc.WebOptions.RelyOnCSS = false;
                doc.WebOptions.OrganizeInFolder = false;

                doc.SaveAs(ref oFileName, ref oFormat, ref _oFalse, ref _Missing,
                            ref _Missing, ref _Missing, ref _Missing, ref _Missing,
                            ref _Missing, ref _Missing, ref _Missing, ref _Missing,
                            ref _Missing, ref _Missing, ref _Missing, ref _Missing);
            }
            catch( Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                ((_Document)doc).Close(ref _Missing, ref _Missing, ref _Missing);
                Marshal.ReleaseComObject(doc);
                doc = null;

                GC.Collect();
            }

            return File.Exists(htmlFileName) ? htmlFileName : null;
        }        

        private Document OpenDocument(string localFile)
        {
            var instance = GetWinWordComObject();
            if (instance == null)
                return null;

            object olocalFile = localFile;

            var doc = instance.Documents.Open(ref olocalFile, ref _oFalse, ref _oFalse, ref _oFalse, ref _Missing,
                ref _Missing, ref _Missing, ref _Missing, ref _Missing, ref _Missing, ref _Missing, ref _oFalse,
                ref _Missing, ref _Missing, ref _Missing, ref _Missing);

            return doc;
        }

        public void CleanUpTempFiles()
        {
            //delete all oour temp files and folders
            if (_TempFiles != null && _TempFiles.Count > 0)
            {
                foreach (var file in _TempFiles)
                {
                    if (File.Exists(file))
                        File.Delete(file);
                }
            }

            _TempFiles = new List<string>();
        }

        public void Dispose()
        {
            try
            {
                if (_WinWordInstance != null)
                {
                    if (_WinWordInstance.Documents.Count == 0)
                        _WinWordInstance.Quit(ref _Missing, ref _Missing, ref _Missing);

                    Marshal.ReleaseComObject(_WinWordInstance);
                }
            }
            catch (InvalidComObjectException ex)
            {
                System.Diagnostics.Debug.Write(ex.Message);
            }

            CleanUpTempFiles();
            GC.Collect();
        }
    }
}

Open in new window

Author

Commented:
Thanks for the answers.
RQuadling: I will have to pass with escape characters '\\'  in the code, so can't replace \\ with a \.
zadeveloper: I have to keep the RTF format, I can't convert to HTML. Users need to do changes in it and I have to save it as RTF.
 My goal is to open the text from database in RTF editor and save it back. FreeTextBox or Telerik is not allowing me to do it. Can you guys suggest any other tool or code to do it. Can I open rtf in MS office word in Internet Explorer and save it back.  What I want is word like editor with spell check ability and ability to save in PDF.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Hi again...

I will look further for you...
Richard QuadlingSenior Software Developer

Commented:
nsdlsandy, I don't quite understand your response.

The data you provided is NOT 100% rtf code.

It is, for want of describing it, escaped rtf code.

So, to access it, you have to unescape it.

That's it.

As the data is NOT rtf, no rtf tool can read it. At best it will ignore the \\ and read just the characters, resulting in garbage.

You could use ...

select replace(column, '\\', '\') as column

in the SQL to retrieve the data.

What put the data into the DB to start with. That will be doing the escaping.

Author

Commented:
RQuadling,

Sorry for the confusion.

I agree that the data is escaped rtf code and it has to be that way as I have to get it from database and populate in some editor for users and then save it back. The data in database was saved from some old tool which is absolute now and can't be used.

Initially I got confused with editors like Telerik & FreeTextBox as they claimed to be Rich Text editor too, but now I realize that they are rich text not rich text format(rtf) and that is why rtf format data comes with '\' in those editors.

In short, I need a good, tried and proven rich text format (rtf) editor on web which can be used with ASP.Net web app.
Richard QuadlingSenior Software Developer

Commented:
Aha!

You can run a one off hit to search and replace \\ with \ in the data. At that point, the data will be RTF just fine.

In terms of editing RTF, well, WordPad does it just fine, but that's a GUI app.

It _MAY_ be easier to convert from RTF to whatever format the RichText component wants.

If you do the search and replace, do any of the components you've tried represent the data appropriately?

http://www.richtextbox.com/ was one component which may be of use.

http://www.richtextbox.com/Feature-Comparison-Chart.htm shows that CuteEditor 5.3 and 6.4 support RTF <-> HTML.

I think this is probably the sanest way to work.

Depending upon the final use, you may find simply converting it all to HTML far easier and opens up a LOT more options.

Author

Commented:
Thanks for the responses, I am trying them out and will get back soon

Author

Commented:

I tried RichTextBox to open rtf but it did not work. Even the CuteEditor support people were not able to open it. I guess rtf format was old version.
So finally I got tired and tried to convince users to try HTML rich text. I used zadeveloper code to convert it to html and show up in RichTextBox and that worked except for \tab of rich text.

The \tab  in rich text are showing up as some ascii character codes as squares or spaces. Can you guys help with that?



Richard QuadlingSenior Software Developer

Commented:
TAB is white space.

Can you show the HTML that is being generated?

A live URL would be useful.

Author

Commented:
I don't have a live link but I have attached a screen shot if that helps.
RTF-Screen-shot.jpg
Richard QuadlingSenior Software Developer

Commented:
And what is the HTML of that?

The screen shot is just the rendering of the HTML. Not much use.

Author

Commented:
HTML string for the RTF posted in the queston is as shown below. I have also attached the mage for refernce.


<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=Generator content="Microsoft Word 12 (filtered)">
<style>
<!--
 /* Font Definitions */
 @font-face
      {font-family:"Cambria Math";
      panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
      {font-family:Calibri;
      panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
      {margin-top:0in;
      margin-right:0in;
      margin-bottom:10.0pt;
      margin-left:0in;
      line-height:115%;
      font-size:11.0pt;
      font-family:"Calibri","sans-serif";}
.MsoChpDefault
      {font-size:11.0pt;}
.MsoPapDefault
      {margin-bottom:10.0pt;
      line-height:115%;}
 /* Page Definitions */
 @page Section1
      {size:11.0in 8.5in;
      margin:1.0in 125.0pt 1.0in 125.0pt;}
div.Section1
      {page:Section1;}
 /* List Definitions */
 ol
      {margin-bottom:0in;}
ul
      {margin-bottom:0in;}
-->
</style>

</head>

<body lang=EN-US style='text-justify-trim:punctuation'>

<div class=Section1>

<p class=MsoNormal><font size=3 face="Courier New"><span style='font-size:12.0pt;
line-height:115%;font-family:"Courier New"'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=3 face="Courier New"><span
style='font-size:12.0pt;font-family:"Courier New"'>here</span></font><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt;font-family:
"Courier New";color:black'>THIS REVIEW.</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>PAGE 00     <b><span
style='font-weight:bold'>CERT-LABEL FD</span></b></span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>                  PADED
'DEL-FLAG        1 AN'</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>      </span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>PAGE 000    LINE
02 CHANGED 'PR' TO 'RT'</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>                  04
'INFO-SM' TO </span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>                                 
'COMP-IYBL-DESC-TX'</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>                  TL
05 MDT 'NEWS'</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal;text-autospace:none'><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New";color:black'>IE 00S-00M  JAMBA
JUICE FROM 'SMSMSMS' TO 'IYIY'</span></font></p>

</div>

</body>

</html>

CheckHTML.jpg
Richard QuadlingSenior Software Developer

Commented:
That's a MS Word HTML document.

And EE isn't showing that as anything untoward.

Can you save the HTML as a file and attach?

What happens if you load it into FireFox/Chrome/Safari/Opera.

Author

Commented:
That is right I used Microsoft Office DLL to do conversion from RTF to HTML. I have attached the file.

I have not tried in Firefox or other browsers. We use IE here.





CheckHTML.htm
Richard QuadlingSenior Software Developer

Commented:
I've loaded that HTML file into Chrome, IE (at home).

The file loads fine.

No artifacts that you are seeing.

I see that there are several fonts defined in the document.

I can also tell that the character that is in the HTML that is being a problem is character 0xA0 (160).

This is the "No break space".

I would change character 160 to &nbsp; and you should be OK.

Author

Commented:
Thanks for the information. The file loads fine in IE but the characters are seen in the Editor.
I tried FreeTextBox, Cute Editor and Telerik Editors. All had the same problem.

Can you please suggest how to change character 160 to &nbsp;

I have tried sr.ReadToEnd().Replace(" ", "&nbsp;");

and  that did not do the trick.


Thanks for your patience. This is the last little thing before I can close this question.
Senior Software Developer
Commented:
Try ...

replace(chr(160), "&nbsp;")

I don't know if it is chr(), char(), chr$(), etc. But the purpose of it is to take a number and return the character.

The character is NOT a space. That is character #32. This is character #160. Looks like a space but isn't.

It is a non-breaking space.

So.

If _ is a normal space and # is a non breaking space.

This_is_a_series_of_words_which_would_be_broken_at_the_spaces_to_wrap_text_into_a_smaller_space.

e.g.


This_is_a_series_of_words_which
would_be_broken_at_the_spaces
to_wrap_text_into_a_smaller
space.

But ...

This#is#a#series#of#words#where#the#non-breaking#spaces#would#not#allow#the#line#to#be#broken.


http://forums.asp.net/p/982952/1260762.aspx

rawString = rawString.Replace(Convert.ToChar(160), "&nbsp;");

maybe.

Author

Commented:
Thanks, that was helpful information.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial