コード例 #1
0
ファイル: Program.cs プロジェクト: ststeiger/nrtftree
        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
        private void AddMessage(RtfDocument doc, LogMessage message)
        {
            var logLvel = LogLevel.None;

            if (this.store.HasLogLevelProperty)
            {
                logLvel = (LogLevel)message.IntegerProperty(this.store.LogLevelProperty);
            }
            if (this.byLevel.ContainsKey(logLvel))
            {
                this.byLevel[logLvel] = this.byLevel[logLvel] + 1;
            }
            else
            {
                this.byLevel.Add(logLvel, 1);
            }

            doc.AddText(message.Header.Trim(), this.settings.FormatHead(logLvel));
            doc.AddNewLine();

            var txt = message.Body;

            if (string.IsNullOrWhiteSpace(txt))
            {
                doc.AddNewLine();
                return;
            }
            doc.AddText(txt.Trim(), this.settings.FormatBody(logLvel));
            doc.AddNewLine(3);
        }
コード例 #3
0
ファイル: RtfDocumentTest.cs プロジェクト: ststeiger/nrtftree
        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));
        }
コード例 #4
0
        public void Exportar(System.Windows.Controls.DataGrid dg)
        {
            try
            {
                List <Object> itens = new List <object>((IEnumerable <object>)dg.ItemsSource);

                if (itens != null && itens.Count > 0)
                {
                    Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
                    dlg.FileName   = "dadosLista";
                    dlg.DefaultExt = ".rtf";
                    dlg.Filter     = "Arquivo RTF (.rtf)|*.rtf";

                    Nullable <bool> result = dlg.ShowDialog();

                    if (result == true)
                    {
                        FileStream fs = new FileStream(dlg.FileName, FileMode.Create, FileAccess.ReadWrite);
                        fs.Close();

                        RtfDocument rtfDoc = new RtfDocument(dlg.FileName);

                        StringBuilder sb = new StringBuilder();

                        foreach (DataGridColumn coluna in dg.Columns)
                        {
                            sb.Append(coluna.Header.ToString());
                            sb.Append("\t");
                        }
                        RtfCharFormat rtfCharFormat = new RtfCharFormat();
                        rtfCharFormat.Bold = true;
                        rtfCharFormat.Size = 14;

                        rtfDoc.AddText(sb.ToString(), rtfCharFormat);
                        rtfDoc.AddNewLine();
                        rtfDoc.ResetCharFormat();
                        sb.Clear();

                        foreach (Object item in itens)
                        {
                            foreach (DataGridColumn coluna in dg.Columns)
                            {
                                Binding  binding       = (Binding)((DataGridBoundColumn)coluna).Binding;
                                string   path          = binding.Path.Path;
                                string[] hierarquiaObj = path.Split('.');

                                Object itemAux = item;
                                for (int i = 0; i < hierarquiaObj.Length - 1; i++)
                                {
                                    itemAux = itemAux.GetType().GetProperty(hierarquiaObj[i]).GetValue(itemAux, null);
                                }

                                string prop     = hierarquiaObj[hierarquiaObj.Length - 1];
                                string conteudo = "";
                                if (itemAux.GetType().GetProperty(prop).GetValue(itemAux, null) != null)
                                {
                                    conteudo = itemAux.GetType().GetProperty(prop).GetValue(itemAux, null).ToString();
                                }
                                sb.Append(conteudo);
                                sb.Append("\t");
                            }
                            rtfDoc.AddText(sb.ToString());
                            rtfDoc.AddNewLine();
                            sb.Clear();
                        }
                        rtfDoc.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
ファイル: RtfDocumentTest.cs プロジェクト: Bartizan/nrtftree
        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));
        }