Grid - Export to PDF

Sushi Bar
Menu №Name / MeaningOriginal NameImage
123
 Page 1 of 3, items 1 to 4 of 11.
1
Nigiri Sushi
[ Hand-formed sushi ]
握り寿司 Sushi image
2
Futo Maki Sushi
[ Fat rolls sushi ]
太巻き寿司 Sushi image
3
Oshi Sushi
[ Pressed sushi ]
押し寿司 Sushi image
6
Inari Sushi
[ Stuffed sushi ]
稲荷寿司 Sushi image

Demo Configurator

Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB
This online demo demonstrates the export to PDF feature of RadGrid.
The approach is very straightforward - to export the grid content to PDF format simply use the ExportToPdf() server-side method. You can configure the exporting settings for the grid through the RadGrid.ExportSettings section. Also there is additional sub-category (Pdf) dedicated on various configuration settings for the exported .pdf document. The filter property play a key role if you want to decrease the file size or enable better portability of the stream content for environments which have restrictions. You can compare the size of the files when using different filters.

Instructions

What is demonstrated on this demo:
  • Choose border type from the first ComboBox.
  • Choose whether to display header and footer into the exported file from the second ComboBox.
  • Choose a content filter from the third ComboBox.
  • Click the 'Export to PDF' button on top to export the grid content.
  • See how the images/grid appearance/nested tables in the template column are configured for export.
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page Language="c#" Inherits="Telerik.GridExamplesCSharp.Exporting.ExportToPDF.DefaultCS"CodeFile="DefaultCS.aspx.cs"  %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1"
        UpdatePanelsRenderMode="Inline">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="ConfiguratorPanel1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="ConfiguratorPanel1"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <div class="demo-container" runat="server" id="demoContainer" style="width: 745px">
        <asp:ImageButton ID="DownloadPDF" runat="server" OnClick="DownloadPDF_Click" ImageUrl="~/Grid/Examples/Functionality/Exporting/Export-Word-CSV/images/file-extension-pdf-icon_bigger.png"
            CssClass="pdfButton"></asp:ImageButton>
        <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" GridLines="None" DataSourceID="SqlDataSource1"
            AllowSorting="true" Skin="Black" Width="745px" AllowPaging="True" OnItemCreated="RadGrid1_ItemCreated"
            AutoGenerateColumns="False">
            <ExportSettings IgnorePaging="true" OpenInNewWindow="true">
                <Pdf PageHeight="210mm" PageWidth="297mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm"
                    BorderStyle="Medium" BorderColor="#666666">
                </Pdf>
            </ExportSettings>
            <MasterTableView CommandItemDisplay="Top" DataSourceID="SqlDataSource1" DataKeyNames="ItemID"
                PageSize="4" TableLayout="Fixed">
                <PagerStyle Mode="NumericPages"></PagerStyle>
                <CommandItemTemplate>
                    <asp:Image ID="Image1" runat="server" ImageUrl="Images/Backgr.jpg" AlternateText="Sushi Bar"
                        Width="100%"></asp:Image>
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridBoundColumn DataField="ItemID" DataType="System.Int32" ReadOnly="True"
                        SortExpression="ItemID" UniqueName="ItemID" HeaderText="Menu &#8470;">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn DataField="EnglishName" HeaderText="Name / Meaning" SortExpression="EnglishName"
                        UniqueName="Name">
                        <ItemTemplate>
                            <table style="width: 170px;">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr align="center">
                                    <td>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("EnglishName") %>' Style="font-size: 16px; color: #eeeeee; font-weight: bold;"></asp:Label>
                                    </td>
                                </tr>
                                <tr align="center">
                                    <td>
                                        <asp:Label ID="Label2" runat="server" Text='<%# "[ " + Eval("Description") + " ]" %>'
                                            Style="font-size: 12px; color: #aaaaaa"></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="OriginalName" HeaderText="Original Name" SortExpression="OriginalName"
                        UniqueName="OriginalName">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Image" SortExpression="ItemID" UniqueName="Image">
                        <ItemTemplate>
                            <asp:Image ID="SushiImage" runat="server" ImageUrl='<%# String.Format("Images/Sushi/{0}.jpg", Eval("ItemID")) %>'
                                AlternateText="Sushi image" Width="100px" Height="75px" Style="border: 1px solid #000000;"></asp:Image>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <HeaderStyle HorizontalAlign="Center" Font-Size="16px"></HeaderStyle>
            <ItemStyle HorizontalAlign="Center" Font-Names="Arial Unicode MS" Font-Size="16px"
                ForeColor="#eeeeee"></ItemStyle>
            <AlternatingItemStyle HorizontalAlign="Center" Font-Names="Arial Unicode MS" Font-Size="16px"
                ForeColor="#eeeeee"></AlternatingItemStyle>
        </telerik:RadGrid>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
        SelectCommand="SELECT * FROM [SushiMenu]"></asp:SqlDataSource>
    <qsf:ConfiguratorPanel ID="ConfiguratorPanel1" runat="server" Expanded="true">
        <Views>
            <qsf:View>
                <qsf:ConfiguratorColumn ID="ConfiguratorColumn1" runat="server">
                    <ul class="fb-group">
                        <li>
                            <qsf:ComboBox ID="BordersCombo" runat="server" OnSelectedIndexChanged="BordersCombo_SelectedIndexChanged"
                                AutoPostBack="true" Label="Choose borders type:">
                                <Items>
                                    <telerik:RadComboBoxItem Text="All borders" Value="0" />
                                    <telerik:RadComboBoxItem Text="Outer borders" Value="1" />
                                    <telerik:RadComboBoxItem Text="Top and bottom borders" Value="2" />
                                    <telerik:RadComboBoxItem Text="No borders" Value="3" />
                                </Items>
                            </qsf:ComboBox>
                        </li>
                        <li>
                            <qsf:ComboBox ID="HeaderAndFooterCombo" runat="server" OnSelectedIndexChanged="HeaderAndFooterCombo_SelectedIndexChanged"
                                AutoPostBack="true" Label="Choose header and footer:">
                                <Items>
                                    <telerik:RadComboBoxItem Text="Header and footer" Value="1" />
                                    <telerik:RadComboBoxItem Text="No header and footer" Value="0" />
                                    <telerik:RadComboBoxItem Text="Only header" Value="2" />
                                    <telerik:RadComboBoxItem Text="Only footer" Value="3" />
                                </Items>
                            </qsf:ComboBox>
                        </li>
                        <li>
                            <qsf:ComboBox ID="ContentFilters" runat="server" OnSelectedIndexChanged="ContentFilters_SelectedIndexChanged"
                                AutoPostBack="true" Label="Choose content filter:">
                                <Items>
                                    <telerik:RadComboBoxItem Text="NoFilter " Value="0" />
                                    <telerik:RadComboBoxItem Text="ASCII85 " Value="1" />
                                    <telerik:RadComboBoxItem Text="AsciiHex " Value="2" />
                                    <telerik:RadComboBoxItem Text="Flate  " Value="3" />
                                </Items>
                            </qsf:ComboBox>
                        </li>
                    </ul>
                </qsf:ConfiguratorColumn>
            </qsf:View>
        </Views>
    </qsf:ConfiguratorPanel>
    </form>
</body>
</html>

Find Assistance

Help Us Improve

Was this example helpful?