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

Need help centering RadGrds table in Header for PDF

1 Answer 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 01 Mar 2018, 10:55 PM

Hello,

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. 

 

 

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 06 Mar 2018, 07:54 PM
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:

Markup
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" CellPadding="0"
    GridLines="None"
    OnPreRender="RadGrid1_PreRender"
    Width="800px"
    OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView AutoGenerateColumns="true" DataKeyNames="OrderID" CommandItemDisplay='<%# (RadGrid1.IsExporting) ? GridCommandItemDisplay.Top : GridCommandItemDisplay.None %>'>
        <CommandItemSettings ShowExportToPdfButton="true" />
        <CommandItemTemplate>
            <table style="width: 169mm;">
                <colgroup>
                    <col />
                    <col />
                    <col />
                    <col />
                    <col />
                </colgroup>
                <tr>
                    <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>
                </tr>
                <tr>
                    <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>
                </tr>
                <tr>
                    <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>
                </tr>
            </table>
        </CommandItemTemplate>
    </MasterTableView>
</telerik:RadGrid>

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.
Tags
General Discussions
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Share this question
or