Merge two rtf Files

Source: Internet
Author: User

The rtf file is similar to an xml file. It is a structured and formatted file. Microsoft has defined many tags to form many versions and can also customize tags (you can only Parse them yourself, so it doesn't make much sense, and other rtf readers cannot open), the main mark is {\ rtf1 .....}, enclosed by a pair of curly braces, followed by the rtf + version number, which can be any version number. The content in it is recursive, and there will be many tags. It is enough to know this without going into details.

Check the Code:

private string HeBingRTF(string rtfFile1, string rtfFile2)        {                        System.IO.FileStream fs1 = new System.IO.FileStream(rtfFile1,System.IO.FileMode.Opene.Open);            System.IO.FileStream fs2 = new System.IO.FileStream(rtfFile2,System.IO.FileMode.Opene.Open);
            RichTextBox richTextBox1 = new RichTextBox();            RichTextBox richTextBox2 = new RichTextBox();            richTextBox1.LoadFile(fs1, RichTextBoxStreamType.RichText);            richTextBox2.LoadFile(fs2, RichTextBoxStreamType.RichText);            fs1.Close();            fs2.Close();                        string f1 = richTextBox1.Rtf;
           
string f2=richTextBox2.Rtf; string pre = @"{\rtf1"; string end = @"}";
return pre + f1 + f2 + end;
        }
// Call method richTextBox3.Rtf = HeBingRTF (rtfFile1, rtfFile2 );

 

However, the above Code may be problematic, and the color table cannot be automatically adapted. You should use a clipboard to solve the problem.

            System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject();            data.SetData(System.Windows.Forms.DataFormats.Rtf, rtf);            System.Windows.Forms.Clipboard.SetDataObject(data, true);            richtextbox1.Paste();

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.