This is a migrated thread and some comments may be shown as answers.

Space Between RadDocument Header and Body

1 Answer 200 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 19 Jul 2012, 11:41 PM
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

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 24 Jul 2012, 12:30 PM
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.

Tags
RichTextBox
Asked by
Steve
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or