Radgrid export to PDF grid footer showing up on every page - how to make i show up only on last page.

8 posts, 0 answers
  1. Gregory
    Gregory avatar
    7 posts
    Member since:
    Mar 2008

    Posted 23 May 2014 Link to this post

    Hello folks, 

    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!
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 26 May 2014 in reply to Gregory Link to this post

    Hi Gregory,

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Frank
    Frank avatar
    5 posts
    Member since:
    Aug 2013

    Posted 27 Jun 2014 Link to this post

    I am having the same problem and I also would appreciate an answer. Thanks!
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 29 Jun 2014 in reply to Frank Link to this post

    Hi Frank,

    Did you try the above code snippet? Can you provide the code you are trying.

    Thanks,
    Princy
  6. Frank
    Frank avatar
    5 posts
    Member since:
    Aug 2013

    Posted 01 Jul 2014 in reply to Princy Link to this post

    I guess I am a little confused. It looks like your solution there adds a footer, but does it stop it being generator on every single page in the PDF? Because that is the goal.

    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 Sub
     
    Protected Sub RadGrid1_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
        If isExport Then
            ApplyStylesToPDFExport(e.Item)
        End If
    End Sub
     
    Private 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 If
    End Sub
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Jul 2014 in reply to Frank Link to this post

    Hi Frank,

    Please 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 Sub

    Thanks,
    Princy
  8. Frank
    Frank avatar
    5 posts
    Member since:
    Aug 2013

    Posted 03 Jul 2014 in reply to Princy Link to this post

    Thank you Princy. That worked for getting rid of the footer on every page and also adding the text at the very end. What I need to do now is to replace that text with a calculated value based on values in the grid's data. I am not exactly sure how to do that. Would you point me in the right direction? Thank you so much.
  9. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jul 2014 in reply to Frank Link to this post

    Hi Frank,

    Please try the following code snippet to access values of columns.

    VB:
    Private counter As Integer = 0
    Protected 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 If
    End Sub
    Protected Sub RadGrid1_PdfExporting(sender As Object, e As Telerik.Web.UI.GridPdfExportingArgs) Handles RadGrid1.PdfExporting
      e.RawHTML = e.RawHTML + counter
    End Sub

    Thanks,
    Princy
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017