Need help centering RadGrds table in Header for PDF

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    6 posts
    Member since:
    Jan 2018

    Posted 01 Mar 2018 Link to this post


    I am having trouble centering a RadGrids header when exporting to PDF. If you take a look at the attached file, my table in the header is not aligned. Are you able to adjust the margin within the header?

    Here are my export settings for the pdf

    EadradGrid.ExportSettings.Pdf.PageWidth = Unit.Parse("210mm");
    EadradGrid.ExportSettings.Pdf.PageHeader.LeftCell.Text = " ";
    EadradGrid.ExportSettings.Pdf.PageHeader.MiddleCell.Text = headerLeftCell;
    EadradGrid.ExportSettings.Pdf.PageHeader.RightCell.Text = " ";
    EadradGrid.ExportSettings.Pdf.PageRightMargin = Unit.Parse("20mm");
    EadradGrid.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("20mm");


    It seems that the PageRightMargin and PageLeftMargin only affect the body of the PDF and not the Header. 



  2. Attila Antal
    Attila Antal avatar
    246 posts

    Posted 06 Mar 2018 Link to this post

    Hi Jonathan,

    I was wondering which method did you use to create the header, by setting the PageHeaders?

    You can try to export using the approach from the Grid - Export to PDF demo, which uses the CommandItemtemplate as container of the banner element for Header.

    Here is an example:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" CellPadding="0"
        <MasterTableView AutoGenerateColumns="true" DataKeyNames="OrderID" CommandItemDisplay='<%# (RadGrid1.IsExporting) ? GridCommandItemDisplay.Top : GridCommandItemDisplay.None %>'>
            <CommandItemSettings ShowExportToPdfButton="true" />
                <table style="width: 169mm;">
                        <col />
                        <col />
                        <col />
                        <col />
                        <col />
                        <td style="background-color:blueviolet;"><%# "My String" %></td>
                        <td style="background-color:aqua;">Row1 Cell2</td>
                        <td style="background-color:antiquewhite;">Row1 Cell3</td>
                        <td style="background-color:aquamarine;">Row1 Cell4</td>
                        <td style="background-color:bisque;">Row1 Cell5</td>
                        <td style="background-color:burlywood;">Row2 Cell1</td>
                        <td style="background-color:cadetblue;">Row2 Cell2</td>
                        <td style="background-color:chocolate;">Row2 Cell3</td>
                        <td style="background-color:coral;">Row2 Cell4</td>
                        <td style="background-color:cornflowerblue;">Row2 Cell5</td>
                        <td style="background-color:crimson;">Row3 Cell1</td>
                        <td style="background-color:darkcyan;">Row3 Cell2</td>
                        <td style="background-color:darkkhaki;">Row3 Cell3</td>
                        <td style="background-color:darkorange;">Row3 Cell4</td>
                        <td style="background-color:darkturquoise;">Row3 Cell5</td>

    C# - PreRender event handler adjusting the settings
    protected void RadGrid1_PreRender(object sender, EventArgs e)
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.GridLines = GridLines.Both;
        if (RadGrid1.IsExporting)
            RadGrid1.ExportSettings.Pdf.PageTopMargin = Unit.Parse("0mm");
            RadGrid1.ExportSettings.Pdf.PageBottomMargin = Unit.Parse("0mm");
            RadGrid1.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("20mm");
            RadGrid1.ExportSettings.Pdf.PageRightMargin = Unit.Parse("20mm");
            RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("210mm");
            RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("110mm");

    Please check out the attached sample for demonstration as well the screenshot about the results.

    I hope this will prove helpful.

    Kind regards,
    Attila Antal
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top