Пример #1
0
        private void btnFromClipBoard_Click(object sender, EventArgs e)
        {
            tvRtfStruct.Nodes.Clear();

            IDataObject ido = Clipboard.GetDataObject();

            if (ido.GetDataPresent(DataFormats.Rtf))
            {
                string         rtf = (string)ido.GetData(DataFormats.Rtf);
                RTFDomDocument doc = new RTFDomDocument();
                doc.LoadRTFText(rtf);

                foreach (RTFDomElement element in doc.Elements)
                {
                    TreeNode tn1stLevel = new TreeNode(element.GetType().ToString());
                    tn1stLevel.ToolTipText = element.InnerText;
                    tvRtfStruct.Nodes.Add(tn1stLevel);
                    ConstructNodeStruct(tn1stLevel, element);
                }
            }
            else
            {
                MessageBox.Show("剪切板中没有rft格式的内容");
            }
        }
Пример #2
0
 /// <summary>
 /// 从指定的RTF字符串加载RTF文档
 /// </summary>
 /// <param name="rtf">RTF文档字符串</param>
 public virtual bool LoadRTFText(string rtf)
 {
     _RTFDocument.LoadRTFText(rtf);
     _RTFDocument.FixForParagraphs(_RTFDocument);
     //format.Reset();
     //CurrentParagraphEOF = null;
     return(true);
 }
Пример #3
0
        public static void RtfToDomTree(string rtf)
        {
            RTFDomDocument doc = new RTFDomDocument();

            doc.LoadRTFText(rtf);

            // MessageBox.Show(doc.InnerText); // convert to plain text
            MessageBox.Show(doc.ToDomString());
        }
Пример #4
0
 public void TestLoadRTFText()
 {
     var document = new RTFDomDocument();
     document.LoadRTFText(@"{\rtf1\fbidis\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Segoe UI;}{\f1\fnil Segoe UI;}}
     {\colortbl ;\red0\green0\blue0;\red255\green0\blue0;\red0\green0\blue255;\red0\green128\blue0;}
     {\*\generator Riched20 6.3.9600}\viewkind4\uc1
     \pard\ltrpar\tx720\cf1\f0\fs28 black\cf2 red\cf3 blue\cf4 green\par
     green\b and\cf1 bold\b0 andnot\cf4\f1\par
     }
     ");
     CollectionAssert.IsNotEmpty(document.Elements);
 }
Пример #5
0
        public static string ConvertToHTML(string rtf)
        {
            var before = Stopwatch.StartNew();
            var doc    = new RTFDomDocument();

            doc.LoadRTFText(rtf);

            var htmlDoc = new StringBuilder();

            htmlDoc.Append("<html><head></head><body>");
            htmlDoc.Append(ConvertElementsToHTML(doc.Elements));
            htmlDoc.Append("</body></html>");
            return(htmlDoc.ToString());
        }
Пример #6
0
        private void btnLoadClipboardRTF_Click(object sender, EventArgs e)
        {
            IDataObject ido = Clipboard.GetDataObject();

            if (ido.GetDataPresent(DataFormats.Rtf))
            {
                string         rtf = ( string )ido.GetData(DataFormats.Rtf);
                RTFDomDocument doc = new RTFDomDocument();
                doc.Progress += new ProgressEventHandler(doc_Progress);
                doc.LoadRTFText(rtf);
                txtRTFDom.Text   = doc.ToDomString();
                this.Text        = "";
                myProgress.Value = 0;
            }
        }
Пример #7
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            tvRtfStruct.Nodes.Clear();

            RTFDomDocument doc = new RTFDomDocument();

            doc.LoadRTFText(txtRtfContent.Rtf);
            foreach (RTFDomElement element in doc.Elements)
            {
                TreeNode tn1stLevel = new TreeNode(element.GetType().ToString());
                tn1stLevel.ToolTipText = element.InnerText;
                tvRtfStruct.Nodes.Add(tn1stLevel);
                ConstructNodeStruct(tn1stLevel, element);
            }
        }
Пример #8
0
        public void ShouldLoadFromFile(string fileName, int length)
        {
            var file = Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources", fileName + ".rtf");

            var doc = new RTFDomDocument();

            doc.Load(file);
            var text = doc.ToDomString();

            Assert.AreEqual(length, text.Length);

            doc = new RTFDomDocument();
            doc.LoadRTFText(File.ReadAllText(file));
            var rtfText = doc.ToDomString();

            Assert.AreEqual(text, rtfText);
        }