Пример #1
0
        public void Write(RTFWriter writer)
        {
            writer.WriteStartGroup( );
            writer.WriteKeyword("info");
            foreach (string strKey in myInfo.Keys)
            {
                writer.WriteStartGroup();
                if (strKey == "edmins" ||
                    strKey == "vern" ||
                    strKey == "nofpages" ||
                    strKey == "nofwords" ||
                    strKey == "nofchars" ||
                    strKey == "nofcharsws" ||
                    strKey == "id")
                {
                    writer.WriteKeyword(strKey + myInfo[strKey]);
                }
                else
                {
                    writer.WriteKeyword(strKey);
                    writer.WriteText(myInfo[strKey]);
                }
                writer.WriteEndGroup();
            }
            writer.WriteStartGroup();

            WriteTime(writer, "creatim", dtmCreatim);
            WriteTime(writer, "revtim", dtmRevtim);
            WriteTime(writer, "printim", dtmPrintim);
            WriteTime(writer, "buptim", dtmBuptim);

            writer.WriteEndGroup();
        }
Пример #2
0
 public virtual bool Open(string strFileName)
 {
     myWriter          = new RTFWriter(strFileName);
     myWriter.Encoding = System.Text.Encoding.GetEncoding(936);
     myWriter.Indent   = false;
     return(true);
 }
Пример #3
0
 public virtual bool Open(System.IO.TextWriter writer)
 {
     myWriter          = new RTFWriter(writer);
     myWriter.Encoding = System.Text.Encoding.GetEncoding(936);
     myWriter.Indent   = false;
     return(true);
 }
Пример #4
0
        /// <summary>
        /// Test generate rtf file
        /// after execute this function you can open c:\a.rtf
        /// </summary>
        internal static void TestWriteFile( )
        {
            RTFWriter w = new RTFWriter("c:\\a.rtf");

            TestBuildRTF(w);
            w.Close();
            System.Windows.Forms.MessageBox.Show("OK , you can open file c:\\a.rtf 了.");
        }
Пример #5
0
 /// <summary>
 /// Save rtf to a stream
 /// </summary>
 /// <param name="stream">stream</param>
 public void Save(System.IO.Stream stream)
 {
     using (RTFWriter writer = new RTFWriter(new System.IO.StreamWriter(stream, this.Encoding)))
     {
         this.Write(writer);
         writer.Close();
     }
 }
Пример #6
0
 /// <summary>
 /// save rtf file
 /// </summary>
 /// <param name="strFileName">file name</param>
 public void Save(string strFileName)
 {
     using (RTFWriter writer = new RTFWriter(strFileName))
     {
         this.Write(writer);
         writer.Close();
     }
 }
Пример #7
0
 /// <summary>
 /// write content to rtf document
 /// </summary>
 /// <param name="writer">RTF text writer</param>
 public override void Write(RTFWriter writer)
 {
     writer.WriteStartGroup();
     foreach (RTFNode node in myNodes)
     {
         node.Write(writer);
     }
     writer.WriteEndGroup();
 }
Пример #8
0
        /// <summary>
        /// Test generate rtf text and copy to windows clipboard
        /// after execute this function , you can paste rtf text in MS Word
        /// </summary>
        internal static void TestClipboard()
        {
            System.IO.StringWriter myStr = new System.IO.StringWriter();
            RTFWriter w = new RTFWriter(myStr);

            TestBuildRTF(w);
            w.Close();
            System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject();
            data.SetData(System.Windows.Forms.DataFormats.Rtf, myStr.ToString());
            System.Windows.Forms.Clipboard.SetDataObject(data, true);
            System.Windows.Forms.MessageBox.Show("OK, you can paste words in MS Word.");
        }
Пример #9
0
        /// <summary>
        /// test
        /// </summary>
        internal static void Test()
        {
            RTFRawDocument doc = new RTFRawDocument();

            doc.Load(@"d:\abc.rtf");
            //System.Console.WriteLine( doc.Text );
            RTFWriter writer = new RTFWriter(@"d:\a.rtf");

            writer.Indent = true;
            doc.Write(writer);
            writer.Close();
        }
Пример #10
0
 private void WriteTime(RTFWriter writer, string name, DateTime Value)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(name);
     writer.WriteKeyword("yr" + Value.Year);
     writer.WriteKeyword("mo" + Value.Month);
     writer.WriteKeyword("dy" + Value.Day);
     writer.WriteKeyword("hr" + Value.Hour);
     writer.WriteKeyword("min" + Value.Minute);
     writer.WriteKeyword("sec" + Value.Second);
     writer.WriteEndGroup();
 }
Пример #11
0
 /// <summary>
 /// 输出颜色表
 /// </summary>
 /// <param name="writer">RTF文档书写器</param>
 public void Write(RTFWriter writer)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(RTFConsts._colortbl);
     writer.WriteRaw(";");
     for (int iCount = 0; iCount < myItems.Count; iCount++)
     {
         System.Drawing.Color c = (System.Drawing.Color)myItems[iCount];
         writer.WriteKeyword("red" + c.R);
         writer.WriteKeyword("green" + c.G);
         writer.WriteKeyword("blue" + c.B);
         writer.WriteRaw(";");
     }
     writer.WriteEndGroup();
 }
Пример #12
0
 /// <summary>
 /// Test to generate a little rtf document
 /// </summary>
 /// <param name="w">RTF text writer</param>
 private static void TestBuildRTF(RTFWriter w)
 {
     w.Encoding = System.Text.Encoding.GetEncoding(936);
     // write header
     w.WriteStartGroup();
     w.WriteKeyword("rtf1");
     w.WriteKeyword("ansi");
     w.WriteKeyword("ansicpg" + w.Encoding.CodePage);
     // wirte font table
     w.WriteStartGroup();
     w.WriteKeyword("fonttbl");
     w.WriteStartGroup();
     w.WriteKeyword("f0");
     w.WriteText("Arial;");
     w.WriteEndGroup();
     w.WriteStartGroup();
     w.WriteKeyword("f1");
     w.WriteText("Times New Roman;");
     w.WriteEndGroup();
     w.WriteEndGroup();
     // write color table
     w.WriteStartGroup();
     w.WriteKeyword("colortbl");
     w.WriteText(";");
     w.WriteKeyword("red0");
     w.WriteKeyword("green0");
     w.WriteKeyword("blue255");
     w.WriteText(";");
     w.WriteEndGroup();
     // write content
     w.WriteKeyword("qc");               // set alignment center
     w.WriteKeyword("f0");               // set font
     w.WriteKeyword("fs30");             // set font size
     w.WriteText("This is the first paragraph text ");
     w.WriteKeyword("cf1");              // set text color
     w.WriteText("Arial ");
     w.WriteKeyword("cf0");              // set default color
     w.WriteKeyword("f1");               // set font
     w.WriteText("Align center ABC12345");
     w.WriteKeyword("par");              // new paragraph
     w.WriteKeyword("pard");             // clear format
     w.WriteKeyword("f1");               // set font
     w.WriteKeyword("fs20");             // set font size
     w.WriteKeyword("cf1");
     w.WriteText("This is the secend paragraph Arial left alignment ABC12345");
     // finish
     w.WriteEndGroup();
 }
Пример #13
0
 /// <summary>
 /// Write font table rtf
 /// </summary>
 /// <param name="writer">rtf text writer</param>
 public void Write(RTFWriter writer)
 {
     writer.WriteStartGroup();
     writer.WriteKeyword(RTFConsts._fonttbl);
     foreach (RTFFont item in this)
     {
         writer.WriteStartGroup();
         writer.WriteKeyword("f" + item.Index);
         if (item.Charset != 0)
         {
             writer.WriteKeyword("fcharset" + item.Charset);
         }
         writer.WriteText(item.Name);
         writer.WriteEndGroup();
     }
     writer.WriteEndGroup();
 }
Пример #14
0
 /// <summary>
 /// write to rtf document
 /// </summary>
 /// <param name="writer">RTF text writer</param>
 public virtual void Write(RTFWriter writer)
 {
     if (intType == RTFNodeType.Control ||
         intType == RTFNodeType.Keyword ||
         intType == RTFNodeType.ExtKeyword)
     {
         if (this.bolHasParameter)
         {
             writer.WriteKeyword(
                 this.strKeyword + this.intParameter,
                 this.intType == RTFNodeType.ExtKeyword);
         }
         else
         {
             writer.WriteKeyword(
                 this.strKeyword,
                 this.intType == RTFNodeType.ExtKeyword);
         }
     }
     else if (intType == RTFNodeType.Text)
     {
         writer.WriteText(this.strKeyword);
     }
 }
Пример #15
0
 /// <summary>
 /// write rtf
 /// </summary>
 /// <param name="writer">RTF writer</param>
 public override void Write(RTFWriter writer)
 {
     writer.Encoding = this.Encoding;
     base.Write(writer);
 }