Space Between RadDocument Header and Body

2 posts, 0 answers
  1. Steve
    Steve avatar
    124 posts
    Member since:
    Jun 2011

    Posted 19 Jul 2012 Link to this post

    I've tried to no avail to remove the space between my header and the body of my document.  Is there any way to do this?  See my attached image.
    Thanks in advance,
    Steve

  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 24 Jul 2012 Link to this post

    Hi Steve,

    This scenario has its limitations caused by the fact that a table cannot be the first element in the document and must always be followed by a paragraph. However with some customization document with smaller space between header and body can be created using the following code:
    public RadDocument CreateDocument()
    {
        RadDocument mainDocument = new RadDocument();
        mainDocument.LayoutMode = DocumentLayoutMode.Paged;
        Section mainSection = new Section();
        mainDocument.Sections.Add(mainSection);
        Table table = new Table(4, 4);
        table.Borders = new TableBorders(new Telerik.Windows.Documents.Model.Border(2.5f, BorderStyle.Dotted, Colors.Black));
        mainSection.Blocks.Add(table);
     
        var lastPageParagraph = CreateParagraph();
        lastPageParagraph.Inlines.Add(CreateSpan(string.Format("Number of Rows: {0}", 4)));
        mainSection.Blocks.Add(lastPageParagraph);
        mainDocument.MeasureAndArrangeInDefaultSize();
     
        mainSection.HasDifferentFirstPageHeaderFooter = true;
     
        mainSection.Headers.Default = new Header() { Body = this.CreateDocumentWithContent() };
        mainSection.Headers.First = new Header()
        {
            Body = this.CreateDocumentWithContent(tableParameter =>
            {
                TableRow additionalRow = new TableRow();
                TableCell additionalCell = new TableCell();
                additionalCell.ColumnSpan = 3;
                Paragraph additionalParagraph = CreateParagraph();
                Span additionalSpan = this.CreateSpan("text");
                additionalParagraph.Inlines.Add(additionalSpan);
                additionalCell.Blocks.Add(additionalParagraph);
                additionalRow.Cells.Add(additionalCell);
                tableParameter.AddRow(additionalRow);
            })
        };
     
        return mainDocument;
    }
     
    private RadDocument CreateDocumentWithContent(Action<Table> additionalContent = null)
    {
        RadDocument document = new RadDocument();
        Section section = new Section();
        section.PageMargin = new Padding(0);
     
        Table table = new Table();
        table.Borders = new TableBorders(new Telerik.Windows.Documents.Model.Border(2.5f, BorderStyle.Dashed, Colors.Black));
        TableRow row = new TableRow();
        TableCell first = new TableCell();
        TableCell second = new TableCell() { TextAlignment = RadTextAlignment.Center };
        TableCell third = new TableCell() { TextAlignment = RadTextAlignment.Right };
        row.Cells.Add(first);
        row.Cells.Add(second);
        row.Cells.Add(third);
        table.AddRow(row);
     
        if (additionalContent != null)
        {
            additionalContent.Invoke(table);
        }
     
        section.Blocks.Add(table);
     
        Paragraph lastParagraph = CreateParagraph();
        lastParagraph.FontSize = 2;
        lastParagraph.SpacingAfter = 0;
        section.Blocks.Add(lastParagraph);
        document.Sections.Add(section);
        return document;
    }
     
    private Span CreateSpan(string text)
    {
        return new Span(text) { FontSize = 14 };
    }
     
    private static Paragraph CreateParagraph()
    {
        return new Paragraph() { SpacingAfter = 10 };
    }

    Finally assign the created RadDocument to the Document property of the RadRichTextBox to observe the result.

    Don't hesitate to contact us if you have other questions.


    Greetings,
    Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top