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

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

16 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gregory
Top achievements
Rank 1
Gregory asked on 23 May 2014, 04:23 PM
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!

16 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 May 2014, 08:34 AM
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
0
Frank
Top achievements
Rank 1
answered on 27 Jun 2014, 12:25 PM
I am having the same problem and I also would appreciate an answer. Thanks!
0
Princy
Top achievements
Rank 2
answered on 30 Jun 2014, 04:33 AM
Hi Frank,

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

Thanks,
Princy
0
Frank
Top achievements
Rank 1
answered on 01 Jul 2014, 01:26 PM
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
0
Princy
Top achievements
Rank 2
answered on 02 Jul 2014, 05:46 AM
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
0
Frank
Top achievements
Rank 1
answered on 03 Jul 2014, 12:22 PM
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.
0
Princy
Top achievements
Rank 2
answered on 03 Jul 2014, 01:05 PM
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
0
Ghezzo
Top achievements
Rank 1
answered on 23 Apr 2020, 10:19 AM

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

0
Doncho
Telerik team
answered on 28 Apr 2020, 08:41 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ghezzo
Top achievements
Rank 1
answered on 28 Apr 2020, 10:08 AM

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

0
Eyup
Telerik team
answered on 01 May 2020, 09:02 AM

Hello Maurizio,

 

You can achieve this requirement using one of these options:

1. RadGrid:
https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/exporting/export-formats/pdf-export#page-break

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ghezzo
Top achievements
Rank 1
answered on 04 May 2020, 08:56 AM

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

0
Eyup
Telerik team
answered on 07 May 2020, 04:53 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ghezzo
Top achievements
Rank 1
answered on 07 May 2020, 06:26 AM

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

0
Eyup
Telerik team
answered on 12 May 2020, 05:20 AM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Ghezzo
Top achievements
Rank 1
answered on 12 May 2020, 06:53 AM

Ty Eyup. IT WORKING.

best regards

Tags
Grid
Asked by
Gregory
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Frank
Top achievements
Rank 1
Ghezzo
Top achievements
Rank 1
Doncho
Telerik team
Eyup
Telerik team
Share this question
or