Пример #1
0
        public static void Create()
        {
            RtfDocument doc = new RtfDocument(System.Text.Encoding.UTF8);



            RtfCharFormat format = new RtfCharFormat();

            format.Size      = 20;
            format.Bold      = true;
            format.Underline = true;

            format.Color = System.Drawing.Color.Red;


            doc.AddText("Title", format);
            doc.AddNewLine();
            doc.AddNewLine();

            format.Size      = 12;
            format.Bold      = false;
            format.Underline = false;

            doc.AddText("This is a test.", format);
            doc.AddText("This is a text.");

            doc.AddNewLine();

            // doc.AddImage("test.png", 50, 50);

            doc.Save(@"D:\rtfdoc.rtf");
        }
Пример #2
0
 /// <summary>
 /// Сохраняет отчет в файл RTF.
 /// </summary>
 /// <param name="pathToRtfFile">Путь к файлу.</param>
 /// <param name="rtfDocument"></param>
 public static void Save(string pathToRtfFile, RtfDocument rtfDocument)
 {
     if (rtfDocument == null)
     {
         throw new Exception("Отчет для сохранения не был сгенерирован.");
     }
     rtfDocument.Save(pathToRtfFile);
 }
Пример #3
0
        public void AddNewFileToProject(string project, string file)
        {
            string path = ProjectsPath + "\\" + project + "\\Files\\" + file + ".rtf";

            if (File.Exists(path))
            {
                return;
            }
            RtfDocument doc = new RtfDocument();

            doc.Save(path);
            Notes[project].Files.Add(new LoadedFile(path, ProjectsPath + "\\" + project));
        }
Пример #4
0
        /// <summary>
        /// Отчет из плагина
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="someobjs"></param>
        public static void ReportMake(string fileName, IList <VeloObject> someobjs,
                                      float sectionFontSize = 8.5f, PaperOrientation paperOrientation = PaperOrientation.Portrait)
        {
            var doc = new RtfDocument(PaperSize.A4, paperOrientation, Lcid.Russian);

            RTFWorkingProvider.DocumentMargins(doc,
                                               paperOrientation == PaperOrientation.Landscape ? 2.5f : 1.5f,
                                               paperOrientation == PaperOrientation.Landscape ? 1.5f : 2.5f,
                                               1.5f, 1.5f);

            CreateDocumentTitle(doc);
            CreateDataTable(doc, someobjs, sectionFontSize);
            doc.Save(fileName);
        }
Пример #5
0
        public static void Append()
        {
            RtfDocument doc = new RtfDocument(@"D:\rtfdoc.rtf", System.Text.Encoding.UTF8);


            RtfCharFormat format = new RtfCharFormat();

            format.Size      = 12;
            format.Bold      = false;
            format.Underline = false;
            format.Color     = System.Drawing.Color.Blue;

            doc.AddText("This is a test.", format);
            doc.AddText("This is a {bad} text.");


            doc.Save(@"D:\rtfdoc1.rtf");
        }
Пример #6
0
        public void CreateSimpleDocument()
        {
            RtfDocument doc = new RtfDocument();

            RtfCharFormat charFormat = new RtfCharFormat();

            charFormat.Color     = Color.DarkBlue;
            charFormat.Underline = true;
            charFormat.Bold      = true;
            doc.UpdateCharFormat(charFormat);

            RtfParFormat parFormat = new RtfParFormat();

            parFormat.Alignment = TextAlignment.Justified;
            doc.UpdateParFormat(parFormat);

            doc.AddText("First Paragraph");
            doc.AddNewParagraph(2);

            doc.SetFormatBold(false);
            doc.SetFormatUnderline(false);
            doc.SetFormatColor(Color.Red);

            doc.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis eros at tortor pharetra laoreet. Donec tortor diam, imperdiet ut porta quis, congue eu justo.");
            doc.AddText("Quisque viverra tellus id mauris tincidunt luctus. Fusce in interdum ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.");
            doc.AddText("Donec ac leo justo, vitae rutrum elit. Nulla tellus elit, imperdiet luctus porta vel, consectetur quis turpis. Nam purus odio, dictum vitae sollicitudin nec, tempor eget mi.");
            doc.AddText("Etiam vitae porttitor enim. Aenean molestie facilisis magna, quis tincidunt leo placerat in. Maecenas malesuada eleifend nunc vitae cursus.");
            doc.AddNewParagraph(2);

            doc.Save("..\\..\\testdocs\\rtfdocument1.rtf");

            string text1    = doc.Text;
            string rtfcode1 = doc.Rtf;

            doc.AddText("Second Paragraph", charFormat);
            doc.AddNewParagraph(2);

            charFormat.Font      = "Courier New";
            charFormat.Color     = Color.Green;
            charFormat.Bold      = false;
            charFormat.Underline = false;
            doc.UpdateCharFormat(charFormat);

            doc.SetAlignment(TextAlignment.Left);
            doc.SetLeftIndentation(2);
            doc.SetRightIndentation(2);

            doc.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis eros at tortor pharetra laoreet. Donec tortor diam, imperdiet ut porta quis, congue eu justo.");
            doc.AddText("Quisque viverra tellus id mauris tincidunt luctus. Fusce in interdum ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.");
            doc.AddText("Donec ac leo justo, vitae rutrum elit. Nulla tellus elit, imperdiet luctus porta vel, consectetur quis turpis. Nam purus odio, dictum vitae sollicitudin nec, tempor eget mi.");
            doc.AddText("Etiam vitae porttitor enim. Aenean molestie facilisis magna, quis tincidunt leo placerat in. Maecenas malesuada eleifend nunc vitae cursus.");
            doc.AddNewParagraph(2);

            doc.UpdateCharFormat(charFormat);
            doc.SetFormatUnderline(false);
            doc.SetFormatItalic(true);
            doc.SetFormatColor(Color.DarkBlue);

            doc.SetLeftIndentation(0);

            doc.AddText("Test Doc. Петяв ñáéíó\n");
            doc.AddNewLine(1);
            doc.AddText("\tStop.");

            string text2    = doc.Text;
            string rtfcode2 = doc.Rtf;

            doc.Save("..\\..\\testdocs\\rtfdocument2.rtf");

            StreamReader sr = null;

            sr = new StreamReader("..\\..\\testdocs\\rtfdocument1.rtf");
            string rtf1 = sr.ReadToEnd();

            sr.Close();

            sr = null;
            sr = new StreamReader("..\\..\\testdocs\\rtfdocument2.rtf");
            string rtf2 = sr.ReadToEnd();

            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\rtf4.txt");
            string rtf4 = sr.ReadToEnd();

            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\rtf6.txt");
            string rtf6 = sr.ReadToEnd();

            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\doctext1.txt");
            string doctext1 = sr.ReadToEnd();

            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\doctext2.txt");
            string doctext2 = sr.ReadToEnd() + " Петяв ñáéíó\r\n\r\n\tStop.\r\n";

            sr.Close();

            //Se adapta el lenguaje al del PC donde se ejecutan los tests
            int deflangInd = rtf4.IndexOf("\\deflang3082");

            rtf4 = rtf4.Substring(0, deflangInd) + "\\deflang" + CultureInfo.CurrentCulture.LCID + rtf4.Substring(deflangInd + 8 + CultureInfo.CurrentCulture.LCID.ToString().Length);

            //Se adapta el lenguaje al del PC donde se ejecutan los tests
            int deflangInd2 = rtf6.IndexOf("\\deflang3082");

            rtf6 = rtf6.Substring(0, deflangInd2) + "\\deflang" + CultureInfo.CurrentCulture.LCID + rtf6.Substring(deflangInd2 + 8 + CultureInfo.CurrentCulture.LCID.ToString().Length);

            Assert.That(rtf1, Is.EqualTo(rtf6));
            Assert.That(rtf2, Is.EqualTo(rtf4));

            Assert.That(text1, Is.EqualTo(doctext1));
            Assert.That(text2, Is.EqualTo(doctext2));
        }
Пример #7
0
        public void CreateSimpleDocument()
        {
            RtfDocument doc = new RtfDocument();

            RtfCharFormat charFormat = new RtfCharFormat();
            charFormat.Color = Color.DarkBlue;
            charFormat.Underline = true;
            charFormat.Bold = true;
            doc.UpdateCharFormat(charFormat);

            RtfParFormat parFormat = new RtfParFormat();
            parFormat.Alignment = TextAlignment.Justified;
            doc.UpdateParFormat(parFormat);

            doc.AddText("First Paragraph");
            doc.AddNewParagraph(2);

            doc.SetFormatBold(false);
            doc.SetFormatUnderline(false);
            doc.SetFormatColor(Color.Red);

            doc.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis eros at tortor pharetra laoreet. Donec tortor diam, imperdiet ut porta quis, congue eu justo.");
            doc.AddText("Quisque viverra tellus id mauris tincidunt luctus. Fusce in interdum ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.");
            doc.AddText("Donec ac leo justo, vitae rutrum elit. Nulla tellus elit, imperdiet luctus porta vel, consectetur quis turpis. Nam purus odio, dictum vitae sollicitudin nec, tempor eget mi.");
            doc.AddText("Etiam vitae porttitor enim. Aenean molestie facilisis magna, quis tincidunt leo placerat in. Maecenas malesuada eleifend nunc vitae cursus.");
            doc.AddNewParagraph(2);

            doc.Save("..\\..\\testdocs\\rtfdocument1.rtf");

            string text1 = doc.Text;
            string rtfcode1 = doc.Rtf;

            doc.AddText("Second Paragraph", charFormat);
            doc.AddNewParagraph(2);

            charFormat.Font = "Courier New";
            charFormat.Color = Color.Green;
            charFormat.Bold = false;
            charFormat.Underline = false;
            doc.UpdateCharFormat(charFormat);

            doc.SetAlignment(TextAlignment.Left);
            doc.SetLeftIndentation(2);
            doc.SetRightIndentation(2);

            doc.AddText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis eros at tortor pharetra laoreet. Donec tortor diam, imperdiet ut porta quis, congue eu justo.");
            doc.AddText("Quisque viverra tellus id mauris tincidunt luctus. Fusce in interdum ipsum. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.");
            doc.AddText("Donec ac leo justo, vitae rutrum elit. Nulla tellus elit, imperdiet luctus porta vel, consectetur quis turpis. Nam purus odio, dictum vitae sollicitudin nec, tempor eget mi.");
            doc.AddText("Etiam vitae porttitor enim. Aenean molestie facilisis magna, quis tincidunt leo placerat in. Maecenas malesuada eleifend nunc vitae cursus.");
            doc.AddNewParagraph(2);

            doc.UpdateCharFormat(charFormat);
            doc.SetFormatUnderline(false);
            doc.SetFormatItalic(true);
            doc.SetFormatColor(Color.DarkBlue);

            doc.SetLeftIndentation(0);

            doc.AddText("Test Doc. Петяв ñáéíó\n");
            doc.AddNewLine(1);
            doc.AddText("\tStop.");

            string text2 = doc.Text;
            string rtfcode2 = doc.Rtf;

            doc.Save("..\\..\\testdocs\\rtfdocument2.rtf");

            StreamReader sr = null;
            sr = new StreamReader("..\\..\\testdocs\\rtfdocument1.rtf");
            string rtf1 = sr.ReadToEnd();
            sr.Close();

            sr = null;
            sr = new StreamReader("..\\..\\testdocs\\rtfdocument2.rtf");
            string rtf2 = sr.ReadToEnd();
            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\rtf4.txt");
            string rtf4 = sr.ReadToEnd();
            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\rtf6.txt");
            string rtf6 = sr.ReadToEnd();
            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\doctext1.txt");
            string doctext1 = sr.ReadToEnd();
            sr.Close();

            sr = new StreamReader("..\\..\\testdocs\\doctext2.txt");
            string doctext2 = sr.ReadToEnd() + " Петяв ñáéíó\r\n\r\n\tStop.\r\n";
            sr.Close();

            //Se adapta el lenguaje al del PC donde se ejecutan los tests
            int deflangInd = rtf4.IndexOf("\\deflang3082");
            rtf4 = rtf4.Substring(0, deflangInd) + "\\deflang" + CultureInfo.CurrentCulture.LCID + rtf4.Substring(deflangInd + 8 + CultureInfo.CurrentCulture.LCID.ToString().Length);

            //Se adapta el lenguaje al del PC donde se ejecutan los tests
            int deflangInd2 = rtf6.IndexOf("\\deflang3082");
            rtf6 = rtf6.Substring(0, deflangInd2) + "\\deflang" + CultureInfo.CurrentCulture.LCID + rtf6.Substring(deflangInd2 + 8 + CultureInfo.CurrentCulture.LCID.ToString().Length);

            Assert.That(rtf1, Is.EqualTo(rtf6));
            Assert.That(rtf2, Is.EqualTo(rtf4));

            Assert.That(text1, Is.EqualTo(doctext1));
            Assert.That(text2, Is.EqualTo(doctext2));
        }
Пример #8
0
        private static void Main(string[] args)
        {
            // Create document by specifying paper size and orientation,
            // and default language.
            var doc = new RtfDocument(PaperSize.A4, PaperOrientation.Landscape, Lcid.English);

            // Create fonts and colors for later use
            var times            = doc.CreateFont("Times New Roman");
            var courier          = doc.CreateFont("Courier New");
            var red              = doc.CreateColor(new RtfColor("ff0000"));
            var blue             = doc.CreateColor(new RtfColor(0, 0, 255));
            var white            = doc.CreateColor(new RtfColor(255, 255, 255));
            var colorTableHeader = doc.CreateColor(new RtfColor("76923C"));
            var colorTableRow    = doc.CreateColor(new RtfColor("D6E3BC"));
            var colorTableRowAlt = doc.CreateColor(new RtfColor("FFFFFF"));

            // Don't instantiate RtfTable, RtfParagraph, and RtfImage objects by using
            // ``new'' keyword. Instead, use add* method in objects derived from
            // RtfBlockList class. (See Demos.)
            RtfTable     table;
            RtfParagraph par;
            RtfImage     img;
            // Don't instantiate RtfCharFormat by using ``new'' keyword, either.
            // An addCharFormat method are provided by RtfParagraph objects.
            RtfCharFormat fmt;


            // ==========================================================================
            // Demo 1: Font Setting
            // ==========================================================================
            // If you want to use Latin characters only, it is as simple as assigning
            // ``Font'' property of RtfCharFormat objects. If you want to render Far East
            // characters with some font, and Latin characters with another, you may
            // assign the Far East font to ``Font'' property and the Latin font to
            // ``AnsiFont'' property.
            par           = doc.AddParagraph();
            par.Alignment = Align.Left;
            par.DefaultCharFormat.Font     = times;
            par.DefaultCharFormat.AnsiFont = courier;
            par.SetText("Testing\n");


            // ==========================================================================
            // Demo 2: Character Formatting
            // ==========================================================================
            par = doc.AddParagraph();
            par.DefaultCharFormat.Font = times;
            par.SetText("Demo2: Character Formatting");
            // Besides setting default character formats of a paragraph, you can specify
            // a range of characters to which formatting is applied. For convenience,
            // let's call it range formatting. The following section sets formatting
            // for the 4th, 5th, ..., 8th characters in the paragraph. (Note: the first
            // character has an index of 0)
            fmt          = par.AddCharFormat(4, 8);
            fmt.FgColor  = blue;
            fmt.BgColor  = red;
            fmt.FontSize = 18;
            // Sets another range formatting. Note that when range formatting overlaps,
            // the latter formatting will overwrite the former ones. In the following,
            // formatting for the 8th chacacter is overwritten.
            fmt = par.AddCharFormat(8, 10);
            fmt.FontStyle.AddStyle(FontStyleFlag.Bold);
            fmt.FontStyle.AddStyle(FontStyleFlag.Underline);
            fmt.Font = courier;


            // ==========================================================================
            // Demo 3: Footnote
            // ==========================================================================
            par = doc.AddParagraph();
            par.SetText("Demo3: Footnote");
            // In this example, the footnote is inserted just after the 7th character in
            // the paragraph.
            par.AddFootnote(7).AddParagraph().SetText("Footnote details here.");


            // ==========================================================================
            // Demo 4: Header and Footer
            // ==========================================================================
            // You may use ``Header'' and ``Footer'' properties of RtfDocument objects to
            // specify information to be displayed in the header and footer of every page,
            // respectively.
            par = doc.Footer.AddParagraph();
            par.SetText("Demo4: Page: / Date: Time:");
            par.Alignment = Align.Center;
            par.DefaultCharFormat.FontSize = 15;
            // You may insert control words, including page number, total pages, date and
            // time, into the header and/or the footer.
            par.AddControlWord(12, RtfFieldControlWord.FieldType.Page);
            par.AddControlWord(13, RtfFieldControlWord.FieldType.NumPages);
            par.AddControlWord(19, RtfFieldControlWord.FieldType.Date);
            par.AddControlWord(25, RtfFieldControlWord.FieldType.Time);
            // Here we also add some text in header.
            par = doc.Header.AddParagraph();
            par.SetText("Demo4: Header");


            // ==========================================================================
            // Demo 5: Image
            // ==========================================================================
            img = doc.AddImage("../../demo5.jpg", ImageFileType.Jpg);
            // You may set the width only, and let the height be automatically adjusted
            // to keep aspect ratio.
            img.Width = 130;
            // Place the image on a new page. The ``StartNewPage'' property is also supported
            // by paragraphs and tables.
            //img.StartNewPage = true;
            img.StartNewPara = true;


            // ==========================================================================
            // demo 6: ���
            // ==========================================================================
            // Please be careful when dealing with tables, as most crashes come from them.
            // If you follow steps below, the resulting RTF is not likely to crash your
            // MS Word.
            //
            // Step 1. Plan and draw the table you want on a scratch paper.
            // Step 2. Start with a MxN regular table.
            table = doc.AddTable(5, 4, 415.2f, 12);
            table.Margins[Direction.Bottom] = 20;
            table.SetInnerBorder(BorderStyle.Dotted, 1f);
            table.SetOuterBorder(BorderStyle.Single, 2f);

            table.HeaderBackgroundColor = colorTableHeader;
            table.RowBackgroundColor    = colorTableRow;
            table.RowAltBackgroundColor = colorTableRowAlt;


            // Step 3. (Optional) Set text alignment for each cell, row height, column width,
            //			border style, etc.
            for (var i = 0; i < table.RowCount; i++)
            {
                for (var j = 0; j < table.ColCount; j++)
                {
                    table.Cell(i, j).AddParagraph().SetText("CELL " + i + "," + j);
                }
            }

            // Step 4. Merge cells so that the resulting table would look like the one you drew
            //			on paper. One cell cannot be merged twice. In this way, we can construct
            //			almost all kinds of tables we need.
            table.Merge(1, 0, 3, 1);
            // Step 5. You may start inserting content for each cell. Actually, it is adviced
            //			that the only thing you do after merging cell is inserting content.
            table.Cell(4, 3).BackgroundColor = red;
            table.Cell(4, 3).AddParagraph().SetText("Demo6: Table");


            // ==========================================================================
            // Demo 7: ``Two in one'' format
            // ==========================================================================
            // This format is provisioned for Far East languages. This demo uses Traditional
            // Chinese as an example.
            par = doc.AddParagraph();
            par.SetText("Demo7: aaa�ñƤ�raaa");
            fmt = par.AddCharFormat(10, 13);
            fmt.TwoInOneStyle = TwoInOneStyle.Braces;
            fmt.FontSize      = 16;


            // ==========================================================================
            // Demo 7.1: Hyperlink
            // ==========================================================================
            par = doc.AddParagraph();
            par.SetText("Demo 7.1: Hyperlink to target (Demo9)");
            fmt = par.AddCharFormat(10, 18);
            fmt.LocalHyperlink    = "target";
            fmt.LocalHyperlinkTip = "Link to target";
            fmt.FgColor           = blue;


            // ==========================================================================
            // Demo 8: New page
            // ==========================================================================
            par = doc.AddParagraph();
            par.StartNewPage = true;
            par.SetText("Demo8: New page");


            // ==========================================================================
            // Demo 9: Set bookmark
            // ==========================================================================
            par = doc.AddParagraph();
            par.SetText("Demo9: Set bookmark");
            fmt          = par.AddCharFormat(0, 18);
            fmt.Bookmark = "target";


            // ==========================================================================
            // Save
            // ==========================================================================
            // You may also retrieve RTF code string by calling to render() method of
            // RtfDocument objects.
            doc.Save("Demo.rtf");


            // ==========================================================================
            // Open the RTF file we just saved
            // ==========================================================================
            var p = new Process {
                StartInfo = { FileName = "Demo.rtf" }
            };

            p.Start();
        }