C# RTF constructor library
-
I wrote a RTF document constructor library in C# almost a year ago. I planned to post an article but never had the time and, in fact, I got bored of writing the library itself. The point was creating reports with clean formatted tables, and I could find no free solutions capable of that. I'm sorry for being too lazy to write even a good example. But here is something to look at:
private RtfDocument rtf = new RtfDocument(RtfCodePage.Windows1251); private static RtfFont DefaultFont = new RtfFont("Times New Roman", RtfCharacterSet.Russian, RtfFontFamily.Roman, RtfFontPitch.Variable); private static RtfParagraphFormatting Centered12 = new RtfParagraphFormatting(RtfLanguage.Russian, 12F, RtfTextAlign.Center), LeftAligned12 = new RtfParagraphFormatting(RtfLanguage.Russian), Centered10 = new RtfParagraphFormatting(RtfLanguage.Russian, 10F, RtfTextAlign.Center); private static RtfTableCellStyle LeftAligned12NoBorder = new RtfTableCellStyle(RtfBorderSetting.None, LeftAligned12), Centered12NoBorder = new RtfTableCellStyle(RtfBorderSetting.None, Centered12), Centered10AllBordersVertical = new RtfTableCellStyle(RtfBorderSetting.All, Centered10, RtfTableCellVerticalAlign.Center, RtfTableCellTextFlow.LeftToRightBottomToTop); public RtfExample() { RtfFormattedParagraph empty = new RtfFormattedParagraph(LeftAligned12), p1fp1 = new RtfFormattedParagraph(Centered12), p2fp1 = new RtfFormattedParagraph(LeftAligned12); RtfTableRow p1tr1 = new RtfTableRow(RtfTableAlign.Center); rtf.DefaultLanguage = RtfLanguage.Russian; rtf.FontTable.Add(DefaultFont); empty.IsFormattingIncluded = false; empty.AppendParagraph(); p1tr1.Cells.AddRange(new RtfTableCell\[\] { new RtfTableCell(5.5F, "A table cell", Centered12NoBorder), new RtfTableCell(8.75F, "Another table cell", Centered12NoBorder), }); p1fp1.AppendParagraph(new RtfFormattedText("Sort of header", RtfCharacterFormatting.Bold)); p1fp1.AppendParagraph(); p1fp1.AppendParagraph(); p2fp1.AppendParagraph("Paragraph text"); p2fp1.AppendParagraph(); //Etc. rtf.Contents.AddRange(new IRtfDocumentPart\[\] {
-
I wrote a RTF document constructor library in C# almost a year ago. I planned to post an article but never had the time and, in fact, I got bored of writing the library itself. The point was creating reports with clean formatted tables, and I could find no free solutions capable of that. I'm sorry for being too lazy to write even a good example. But here is something to look at:
private RtfDocument rtf = new RtfDocument(RtfCodePage.Windows1251); private static RtfFont DefaultFont = new RtfFont("Times New Roman", RtfCharacterSet.Russian, RtfFontFamily.Roman, RtfFontPitch.Variable); private static RtfParagraphFormatting Centered12 = new RtfParagraphFormatting(RtfLanguage.Russian, 12F, RtfTextAlign.Center), LeftAligned12 = new RtfParagraphFormatting(RtfLanguage.Russian), Centered10 = new RtfParagraphFormatting(RtfLanguage.Russian, 10F, RtfTextAlign.Center); private static RtfTableCellStyle LeftAligned12NoBorder = new RtfTableCellStyle(RtfBorderSetting.None, LeftAligned12), Centered12NoBorder = new RtfTableCellStyle(RtfBorderSetting.None, Centered12), Centered10AllBordersVertical = new RtfTableCellStyle(RtfBorderSetting.All, Centered10, RtfTableCellVerticalAlign.Center, RtfTableCellTextFlow.LeftToRightBottomToTop); public RtfExample() { RtfFormattedParagraph empty = new RtfFormattedParagraph(LeftAligned12), p1fp1 = new RtfFormattedParagraph(Centered12), p2fp1 = new RtfFormattedParagraph(LeftAligned12); RtfTableRow p1tr1 = new RtfTableRow(RtfTableAlign.Center); rtf.DefaultLanguage = RtfLanguage.Russian; rtf.FontTable.Add(DefaultFont); empty.IsFormattingIncluded = false; empty.AppendParagraph(); p1tr1.Cells.AddRange(new RtfTableCell\[\] { new RtfTableCell(5.5F, "A table cell", Centered12NoBorder), new RtfTableCell(8.75F, "Another table cell", Centered12NoBorder), }); p1fp1.AppendParagraph(new RtfFormattedText("Sort of header", RtfCharacterFormatting.Bold)); p1fp1.AppendParagraph(); p1fp1.AppendParagraph(); p2fp1.AppendParagraph("Paragraph text"); p2fp1.AppendParagraph(); //Etc. rtf.Contents.AddRange(new IRtfDocumentPart\[\] {
Hi KPEBEDKO, imho you might consider posting this code, along with a brief summary statement, on 'Tips and Tricks' ? I'm sure some people would find it valuable. best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
-
Hi KPEBEDKO, imho you might consider posting this code, along with a brief summary statement, on 'Tips and Tricks' ? I'm sure some people would find it valuable. best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
Thank you, Bill. You encouraged me to write the article.