예제 #1
0
        /// <summary>
        /// Return a rich text formatted string from a RTF document object
        /// <seealso cref="RTExporter.RTFDocument">
        /// </summary>
        /// <param name="document">The RTF document to be formatted</param>
        /// <returns>A rich text formatted string</returns>
        public static string ToString(RTFDocument document)
        {
            RTFParser.document = document;

            string str = "{\\rtf1\\ansi\\deff0";

            foreach (RTFParagraph paragraph in document.paragraphs)
            {
                foreach (RTFText text in paragraph.text)
                {
                    document.colors.Add(text.style.color);

                    if (text.style.fontFamily != string.Empty)
                    {
                        document.fonts.Add(text.style.fontFamily);
                    }
                }
            }

            str += FontsParsing();
            str += ColorParsing();

            str += "{\\info {\\author " + document.author + "}";
            DateTime date = DateTime.Now;

            str += "{\\creatim\\yr" + date.Year + "\\mo" + date.Month + "\\dy" + date.Day + "\\hr" + date.Hour + "\\min" + date.Minute + "}";
            str += "{\\version" + document.version + "}";
            str += "{\\edmins0}";
            str += "{\\nofpages1}";
            str += "{\\nofwords0}";
            str += "{\\nofchars0}";
            str += "{\\deftab70}";
            str += "}";

            str += "{\\keywords ";

            foreach (string keyword in document.keywords)
            {
                str += keyword + " ";
            }

            str += "}";

            switch (document.orientation)
            {
            case Orientation.Landscape:
                str += "\\landscape";
                break;

            case Orientation.Portrait:
                str += "\\portrait";
                break;
            }

            str += "\\paperw" + value(document.width) + "\\paperh" + value(document.height) +
                   "\\margl" + value(document.margin.left) + "\\margr" + value(document.margin.right) +
                   "\\margt" + value(document.margin.top) + "\\margb" + value(document.margin.bottom) + " ";

            str += ParagraphParsing();

            str += "}";
            return(str);
        }
예제 #2
0
 public RTFParagraph(RTFDocument document)
 {
     style = new RTFParagraphStyle(document);
     document.paragraphs.Add(this);
 }
예제 #3
0
 /// <summary>
 /// Create or rewrite a file with RTF content
 /// <seealso cref="RTExporter.RTFDocument">
 /// </summary>
 /// <param name="path">The folder path with filename</param>
 /// <param name="document">The RTF document to save</param>
 public static void ToFile(string path, RTFDocument document)
 {
     document.SetFile(path);
     document.Save();
     document.Close();
 }