Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Article Writing
  4. C# RTF constructor library

C# RTF constructor library

Scheduled Pinned Locked Moved Article Writing
csharptutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dima Popov
    wrote on last edited by
    #1

    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\[\] {
    
    B 1 Reply Last reply
    0
    • D Dima Popov

      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\[\] {
      
      B Offline
      B Offline
      BillWoodruff
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • B BillWoodruff

        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

        D Offline
        D Offline
        Dima Popov
        wrote on last edited by
        #3

        Thank you, Bill. You encouraged me to write the article.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups