First off - I know this question (or one very similar) was answered in 2011 via this post called "ExportToPDF footer show on last page RadGrid" as referenced here Footer shows up in every page when export to PDF but the answer page is now 404. So I thought I would ask it again.
Is there a way to get the footer that RadGrid displays at the bottom of the grid on the web page to ONLY show up on the last page of the PDF when exporting to PDF?
I have a RadGrid with grouping, each group has a footer with subtotals, the entire grid has a footer with a an overall total. I tried setting ShowFooter="false" so that I could append a customer footer to the RAWHTML on export but the grid on screen still shows (and exports) all of the footers including the grid level total.
Any help is appreciated.
Thanks!
16 Answers, 1 is accepted
You can use the OnPdfExporting event for your requirement and try the below code snippet.
C#:
protected void RadGrid_PdfExporting(object sender, Telerik.Web.UI.GridPdfExportingArgs e){   string str = "your footer here";   e.RawHTML = e.RawHTML + str;    }Thanks,
Princy
Did you try the above code snippet? Can you provide the code you are trying.
Thanks,
Princy
Here is the code from the code behind (VB)
Protected Sub btnExportToPDF_Click(sender As Object, e As EventArgs) Handles btnExportToPDF.Click    isExport = True    RadGrid1.ExportSettings.ExportOnlyData = True    RadGrid1.ExportSettings.IgnorePaging = True  ' True exports the entire dataset    RadGrid1.ExportSettings.OpenInNewWindow = True    RadGrid1.ExportSettings.FileName = DateTime.Now.Year.ToString() & DateTime.Now.Month.ToString().PadLeft(2, "0"c) & DateTime.Now.Day.ToString().PadLeft(2, "0"c) _                                        & DateTime.Now.Hour.ToString().PadLeft(2, "0"c) & DateTime.Now.Minute.ToString().PadLeft(2, "0"c) & DateTime.Now.Second.ToString().PadLeft(2, "0"c) _                                        & "_" _                                        & DateTime.Now.Millisecond.ToString()    ' Set to landscape size    RadGrid1.ExportSettings.Pdf.PaperSize = Telerik.Web.UI.GridPaperSize.Letter    RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("215mm")    RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("279mm")    RadGrid1.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("13mm")    RadGrid1.ExportSettings.Pdf.PageRightMargin = Unit.Parse("13mm")    RadGrid1.ExportSettings.Pdf.PageTopMargin = Unit.Parse("13mm")    RadGrid1.ExportSettings.Pdf.PageBottomMargin = Unit.Parse("13mm")    RadGrid1.ExportSettings.Pdf.AllowAdd = False    RadGrid1.ExportSettings.Pdf.AllowModify = False    ' Hide the checkbox boolean field during export    If showSelectionCheckboxes Then        RadGrid1.MasterTableView.GetColumn("SelectionCheckbox").Visible = False    End If    RadGrid1.MasterTableView.ExportToPdf()End SubProtected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)    If isExport Then        ApplyStylesToPDFExport(e.Item)    End IfEnd SubPrivate Sub ApplyStylesToPDFExport(ByRef item As Telerik.Web.UI.GridItem)    If TypeOf item Is Telerik.Web.UI.GridHeaderItem Then        item.Style("background-color") = "#D0D0D0"        item.Style("font-family") = "Arial Narrow"        item.Style("font-size") = "6pt"        item.Style("text-align") = "center"    End If    If TypeOf item Is Telerik.Web.UI.GridDataItem Then      ' GridDataItem is a row        ' Set row-level styles        item.Style("background-color") = If(item.ItemType = Telerik.Web.UI.GridItemType.AlternatingItem, "#F0F0F0", "#E0E0E0")        ' Iterate through and set cell-level styles        Dim dataItem As Telerik.Web.UI.GridDataItem = TryCast(item, Telerik.Web.UI.GridDataItem)        For Each col As Telerik.Web.UI.GridColumn In RadGrid1.MasterTableView.Columns            If col.ItemStyle.HorizontalAlign = HorizontalAlign.Right Then                dataItem(col).Style("text-align") = "right"            End If        Next        item.Style("font-family") = "Arial Narrow"        item.Style("font-size") = "6px"    End If    If TypeOf item Is Telerik.Web.UI.GridFooterItem Then        item.Style("background-color") = "#D0D0D0"        item.Style("font-family") = "Arial Narrow"        item.Style("font-size") = "6pt"        item.Style("text-align") = "center"        item.Style("font-weight") = "bold"    End IfEnd SubPlease try the following code snippet. The text comes only at the last page of PDF export. I have attached a screenshot of the output obtained.
ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1" AllowPaging="true" AllowSorting="true">    <MasterTableView DataKeyNames="OrderID">        <Columns>            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID">            </telerik:GridBoundColumn>            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity">            </telerik:GridBoundColumn>            <telerik:GridBoundColumn UniqueName="CustomerID" DataField="CustomerID" HeaderText="CustomerID">            </telerik:GridBoundColumn>            <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" UniqueName="ShipName">            </telerik:GridBoundColumn>        </Columns>    </MasterTableView></telerik:RadGrid><asp:Button ID="btnPDFExport" runat="server" Text="Export to PDF" />VB:
Private isExport As Boolean = False   Protected Sub btnPDFExport_Click(sender As Object, e As System.EventArgs) Handles btnPDFExport.Click       isExport = True       RadGrid1.ExportSettings.ExportOnlyData = True       RadGrid1.ExportSettings.IgnorePaging = True       RadGrid1.ExportSettings.OpenInNewWindow = True       RadGrid1.ExportSettings.Pdf.PaperSize = Telerik.Web.UI.GridPaperSize.Letter       RadGrid1.ExportSettings.Pdf.PageHeight = Unit.Parse("215mm")       RadGrid1.ExportSettings.Pdf.PageWidth = Unit.Parse("279mm")       RadGrid1.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("13mm")       RadGrid1.ExportSettings.Pdf.PageRightMargin = Unit.Parse("13mm")       RadGrid1.ExportSettings.Pdf.PageTopMargin = Unit.Parse("13mm")       RadGrid1.ExportSettings.Pdf.PageBottomMargin = Unit.Parse("13mm")       RadGrid1.ExportSettings.Pdf.AllowAdd = False       RadGrid1.ExportSettings.Pdf.AllowModify = False       RadGrid1.MasterTableView.ExportToPdf()   End Sub   Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated       If isExport Then           ApplyStylesToPDFExport(e.Item)       End If   End Sub   Private Sub ApplyStylesToPDFExport(item As Telerik.Web.UI.GridItem)       If TypeOf item Is Telerik.Web.UI.GridHeaderItem Then           item.Style("font-family") = "Arial Narrow"           item.Style("text-align") = "center"       End If       ' GridDataItem is a row       If TypeOf item Is Telerik.Web.UI.GridDataItem Then           ' Iterate through and set cell-level styles           Dim dataItem As Telerik.Web.UI.GridDataItem = TryCast(item, Telerik.Web.UI.GridDataItem)           For Each col As Telerik.Web.UI.GridColumn In RadGrid1.MasterTableView.Columns               If col.ItemStyle.HorizontalAlign = HorizontalAlign.Right Then                   dataItem(col).Style("text-align") = "right"               End If           Next           item.Style("font-family") = "Lindsey"           item.Style("font-size") = "6px"       End If   End Sub   Protected Sub RadGrid1_PdfExporting(sender As Object, e As Telerik.Web.UI.GridPdfExportingArgs) Handles RadGrid1.PdfExporting       Dim str As String = "Your Text Comes Here!"       e.RawHTML = Convert.ToString(e.RawHTML) & str   End SubThanks,
Princy
Please try the following code snippet to access values of columns.
VB:
Private counter As Integer = 0Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated    If isExport Then      For Each dataItem As GridDataItem In RadGrid1.Items        If Condition Then    counter = counter + Convert.ToInt16(dataItem("UnitPrice").Text)        End If      Next   End IfEnd SubProtected Sub RadGrid1_PdfExporting(sender As Object, e As Telerik.Web.UI.GridPdfExportingArgs) Handles RadGrid1.PdfExporting  e.RawHTML = e.RawHTML + counterEnd SubThanks,
Princy
i had the same problem...but no way...counter is always bigger than my Sum maybe because i must use filter ...or maybe u wrote
if condition then and i dont know what condition i had to write. it work only with one record but with more than one the number in e.rawHTML is always greater. it change any time depending my filter..i dont uderstand why he sum more records.
regards
Maurizio Brusini
 If RadGrid1.IsExporting Then
            For Each dataItem As GridDataItem In RadGrid1.Items
                counter = counter + Convert.ToInt16(dataItem("quant").Text)
            Next
        End If
 Protected Sub RadGrid1_PdfExporting(sender As Object, e As Telerik.Web.UI.GridPdfExportingArgs) Handles RadGrid1.PdfExporting
        '*************************************
              e.RawHTML = Convert.ToString(e.RawHTML) & counter
        '****************************
    End Sub
Hello Maurizio,
To narrow down the issue I would suggest you try the following steps:
1. Try to use Convert.ToDecimal instead of ConverToInt16. The higher than expected sum can be caused by an eventual overflow of the format used.
2. Have in mind the effect of the IgnorePaging property in the RadGrid ExportSettings. If it is disabled (default), the export is made only on the currently visible items on the page.
If the issue remains, you can open a formal support thread and send us a very basic runnable web site to demonstrate the issue you are facing.
Kind regards,
      
Doncho
 Progress Telerik
    
Our thoughts here at Progress are with those affected by the outbreak.
i resolved in this way : in RadGrid1_ItemDataBound event:
Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
            ''****************************************************************
             Dim Valore As Double = item("valore").Text
             totalUnitPrice += Valore
after in RadGrid1_PdfExporting :
Dim str As String = "TOTALE VALORE :    "
        e.RawHTML = e.RawHTML + str
        e.RawHTML = Convert.ToString(e.RawHTML) & totalUnitPrice
BUT it work only in absence of filtering. better than nothing. Still remain one problem, i would like change page in pdf for new group...
best regards
Maurizio Brusini
Hello Maurizio,
You can achieve this requirement using one of these options:
2. RadClientExportManager:
https://demos.telerik.com/aspnet-ajax/client-export-manager/functionality/pdf-multi-page-export/defaultcs.aspx?isNew=true&_ga=2.24976249.299614649.1587883461-1667381012.1451455707
I hope this will prove helpful.
Kind regards,
 
Eyup
 Progress Telerik
    
Our thoughts here at Progress are with those affected by the outbreak.
my grid is gruping, so i would like to know how change page in pdf file when group change...in the example you show me i connot find what i need. i dont know if it is possible.
best regards
Maurizio Brusini
Hello Maurizio,
This can be achieved using the page-break functionality:
1. For the grid approach:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/export-formats/pdf-export#page-break
Here is a sample:
https://www.telerik.com/forums/pdf-export-and-page-break
2. For the ClientExportManager:
You just need to set the PageBreakSelector property:
https://docs.telerik.com/devtools/aspnet-ajax/controls/clientexportmanager/functionality/pdf-multi-page-export
In your case it would be something like:
PageBreakSelector=".rgGroupHeader"Regards,
 
Eyup
 Progress Telerik
    
Our thoughts here at Progress are with those affected by the outbreak.
i have a radgrid with GROUPING
<GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="descr_struttura"></telerik:GridGroupByField>
                        </GroupByFields>
                        <SelectFields>
                            <telerik:GridGroupByField FieldName="descr_struttura" HeaderText="STRUTTURA "></telerik:GridGroupByField>
                            <telerik:GridGroupByField FieldName="valore" HeaderText="         Tot. valore per STRUTTURA "
                                 Aggregate="Sum" />
                        </SelectFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions> 
in your example i dont see how it shd help me. When my gruoup field STRUTTURA change i would like my pdf change page.if it's possible.
best regards
Hi Maurizio,
I've prepared a sample RadGrid web site to demonstrate how you can achieve this requirement.
You can run the Web site by following these steps:1. Open Visual Studio
2. File menu
3. Open option
4. Select Web site and target the web site folder.
5. Include a Bin folder with the Telerik dll assemblies.
Regards,
 
Eyup
 Progress Telerik
    
Our thoughts here at Progress are with those affected by the outbreak.
Ty Eyup. IT WORKING.
best regards

