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

PDF Export not exporting all CommandItemTemplate Items

10 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
david
Top achievements
Rank 1
david asked on 29 Mar 2016, 02:30 PM

similar to this thread regarding CSV export - http://www.telerik.com/forums/csv-export-not-exporting-commanditem-template

my CommandItemTemplate looks like below but only the first control(radlabel) appears in the PDF?

<CommandItemTemplate>

            <telerik:RadLabel ID="RadLabel1" runat="server" Text="Statement" Font-Size="X-Large"></telerik:RadLabel>
            <br />
            <telerik:RadLabel ID="lblDate" runat="server"></telerik:RadLabel>
            <br />
            <hr />
            <table width="100%">
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblflname" runat="server" Font-Bold="true"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblpractLFNAME" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress1" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress1" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress2" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress2" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
            </table>
        </CommandItemTemplate>

10 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 30 Mar 2016, 12:44 PM
Hello David,

Please refer to the following help article that explains how to export TABLE elements while exporting to PDF:
Another option is to use the RadClientExportManager instead and export the grid on client-side:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
david
Top achievements
Rank 1
answered on 30 Mar 2016, 01:59 PM

Thank you for your quick response, but no joy. I changed the markup per the article and only the first label - the one with Text="Statement" appears , none of the radlabels set in codebehind are showing up?

<CommandItemTemplate>
            <table width="800px">
                <colgroup>
                    <col />
                    <col />
                </colgroup>
                <tr>
                    <td>
                        <telerik:RadLabel ID="RadLabel1" runat="server" Text="Statement" Font-Size="X-Large"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <telerik:RadLabel ID="lblDate" runat="server"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblflname" runat="server" Font-Bold="true"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblpractLFNAME" runat="server"></telerik:RadLabel>
                    </td>
                </tr>

                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress1" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress1" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress2" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress2" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
            </table>

0
Konstantin Dikov
Telerik team
answered on 04 Apr 2016, 07:02 AM
Hi David,

I have tested your CommandItemTemplate and if I set the Text property of the Labels in the markup, they are exported correctly on my side.

Could you please elaborate within which event you are setting the text for those labels?


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
david
Top achievements
Rank 1
answered on 04 Apr 2016, 11:25 AM
Hi Konstantin, I am setting the controls in the page_load
0
david
Top achievements
Rank 1
answered on 05 Apr 2016, 03:14 PM

Guessing based on your question, I moved the radlabel text setting to the RadGrid1_ItemDataBound. This improved but did not resolve the incomplete control display. So I added another set of <Col> tags where the controls stopped displaying and it displayed all the controls, this cant be right?

<CommandItemTemplate>
            <table width="1100px">
                <colgroup>
                    <col />
                    <col />
                </colgroup>
                <tr>
                    <td>
                        <telerik:RadLabel ID="lblTitle" runat="server" Text="Statement" Font-Size="X-Large" s></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <telerik:RadLabel ID="lblDate" runat="server"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>       
                <colgroup>
                    <col />
                    <col />
                </colgroup>

                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblflname" runat="server" Font-Bold="true"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblpractLFNAME" runat="server"></telerik:RadLabel>
                    </td>
                </tr>

                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress1" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress1" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress2" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress2" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                 <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>  
            </table>
        </CommandItemTemplate>

0
Konstantin Dikov
Telerik team
answered on 06 Apr 2016, 12:51 PM
Hi David,

I see no problems with the table structure with the correct colgroup setting. Following is the code that I am testing:
<telerik:RadButton runat="server" Text="Export" ID="RadButton1" OnClick="RadButton1_Click"></telerik:RadButton>
 
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemTemplate>
            <table width="1100px">
                <colgroup>
                    <col />
                    <col />
                </colgroup>
                <tr>
                    <td>
                        <telerik:RadLabel ID="lblTitle" runat="server" Text="Statement" Font-Size="X-Large"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <telerik:RadLabel ID="lblDate" runat="server" Text="test"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblflname" runat="server" Font-Bold="true"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblpractLFNAME" Text="test" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
 
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress1" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress1" Text="test" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress2" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress2" Text="test" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>
            </table>
        </CommandItemTemplate>
    </MasterTableView>
</telerik:RadGrid>

And the dummy data:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("FirstName", typeof(string));
    table.Columns.Add("LastName", typeof(string));
    table.Columns.Add("Age", typeof(int));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("BoolValue", typeof(Boolean));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
    }
 
    (sender as RadGrid).DataSource = table;
}
 
protected void RadButton1_Click(object sender, EventArgs e)
{
    RadGrid1.ExportToExcel();
}



Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
david
Top achievements
Rank 1
answered on 06 Apr 2016, 02:44 PM

HI Konstantin

as I said in my earlier post " the markup per the article and only the first label - the one with Text="Statement" appears , none of the radlabels set in codebehind are showing up" so I'm not surprised your example works. Please see my this project for an example of this behaviour. 

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="default.ascx.cs" Inherits="Default" %>

<telerik:RadClientExportManager ID="RadClientExportManager1" runat="server">
    <PdfSettings PageBreakSelector=".pageBreak" />
</telerik:RadClientExportManager>

<hr />
<telerik:RadButton ID="pdfButton" runat="server" OnClick="pdf_Click" Text="Export to PDF">
    <Icon PrimaryIconUrl="~/images/pdf.png" />
</telerik:RadButton>
&nbsp; &nbsp;

<hr />
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" GroupPanelPosition="Top" Width="800px" ShowFooter="true" GridLines="None" CssClass="MyGridView" OnItemDataBound="RadGrid1_ItemDataBound">
    <ExportSettings FileName="Statement.pdf" Pdf-PageLeftMargin="0.25in" Pdf-PageTopMargin="2.0in" HideStructureColumns="true"
        Pdf-PageRightMargin="0.25in" Pdf-PaperSize="Letter" OpenInNewWindow="True">
        <Pdf PageHeight="11.0in" PageLeftMargin="0.25in" PageRightMargin="0.25in" PageWidth="8.5in"
            AllowAdd="false" AllowCopy="true" AllowModify="true" AllowPrinting="true" Author="Anonymous"
            Keywords="None" FontType="Link"
            PaperSize="Legal">
        </Pdf>
    </ExportSettings>
    <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>

    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ShowAddNewRecordButton="False" />
        <CommandItemTemplate>
            <table width="800px">
                <colgroup>
                    <col />
                    <col />
                </colgroup>
                <tr>
                    <td>
                        <telerik:RadLabel ID="RadLabel1" runat="server" Text="Statement" Font-Size="X-Large"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <telerik:RadLabel ID="lblDate" runat="server"></telerik:RadLabel>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <hr />
                    </td>
                    <td>
                        <hr />
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblflname" runat="server" Font-Bold="true"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblpractLFNAME" runat="server"></telerik:RadLabel>
                    </td>
                </tr>

                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress1" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress1" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <telerik:RadLabel ID="lblClientAddress2" runat="server"></telerik:RadLabel>
                    </td>
                    <td align="right">
                        <telerik:RadLabel ID="lblPractAddress2" runat="server"></telerik:RadLabel>
                    </td>
                </tr>
            </table>
        </CommandItemTemplate>
        <CommandItemSettings
            ShowAddNewRecordButton="False" />
    </MasterTableView>
</telerik:RadGrid>

using System;
using System.Data;
using System.Globalization;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class Default : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.DataSource = GetDataTable();
    }

    public void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem)
        {
            GridCommandItem cmditems = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0];

            RadLabel lblflname = (RadLabel)cmditems.FindControl("lblflname");
            lblflname.Text = "John Doe";

            RadLabel lblpractLFNAME = (RadLabel)cmditems.FindControl("lblpractLFNAME");
            lblpractLFNAME.Text = "Dr. Freud";

            RadLabel lblPractAddress1 = (RadLabel)cmditems.FindControl("lblPractAddress1");
            lblPractAddress1.Text = "101 Maple";

            RadLabel lblPractAddress2 = (RadLabel)cmditems.FindControl("lblPractAddress2");
            lblPractAddress2.Text = "Austin, TX";

            RadLabel lblDate = (RadLabel)cmditems.FindControl("lblDate");
            lblDate.Text = string.Format("{0:D}", DateTime.Now);
        }
    }

    protected void pdf_Click(object sender, System.EventArgs e)
    {
        RadGrid1.ExportSettings.ExportOnlyData = false;
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.ExportSettings.OpenInNewWindow = true;
        RadGrid1.ExportSettings.Pdf.AllowPrinting = true;
        RadGrid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Letter;
        RadGrid1.MasterTableView.ExportToPdf();
    }

    public DataTable GetDataTable()
    {
        DataTable table = new DataTable();
        table.Columns.Add("ID", typeof(int));
        table.Columns.Add("FirstName", typeof(string));
        table.Columns.Add("LastName", typeof(string));
        table.Columns.Add("Age", typeof(int));
        table.Columns.Add("Date", typeof(DateTime));
        table.Columns.Add("BoolValue", typeof(Boolean));
        for (int i = 0; i < 5; i++)
        {
            table.Rows.Add(i, "FirstName" + i, "LastName" + i, 20 + i, DateTime.Now.AddDays(i), i % 2 == 0);
        }
        return table;
    }
}

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="Default" %>

<%@ Register TagPrefix="uc1" TagName="HeaderUserControl" Src="Default.ascx" %>
<html>
<body>
    <form runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <uc1:HeaderUserControl runat="server" ID="SCM"></uc1:HeaderUserControl>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

0
Konstantin Dikov
Telerik team
answered on 11 Apr 2016, 09:43 AM
Hi David,

The only issue that I observed with the example is the "800px" width for the table and the fact that the PDF page is smaller and the right content of the CommandItemTemplate is not visible. After changing the width, all labels are displaying correctly. I am attaching a video with the result on my side with our latest version (2016.1 225).


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
david
Top achievements
Rank 1
answered on 11 Apr 2016, 11:52 AM

Thank you Konstantin

changing the table width works, but does result in an odd Grid commanditem  layout when the grid in my project needs to be wider , say 1100px and the grid titles only span 550px in the HTML page but at least they render on the PDF correctly.

It is odd that my solution of setting the table to 1100px displays correctly as expected in the HTML Grid

and when used with a repeated "    <colgroup>
                    <col />
                    <col />
                </colgroup>" mid way down the table HTML does render the commanditem table correctly in the PDF despite the width

 

0
Konstantin Dikov
Telerik team
answered on 14 Apr 2016, 06:59 AM
Hello David,

Since the nested TABLE elements must be with set width in pixels in order for the exporting to PDF to work correctly, the only thing that I could suggest is to either change the width of the TABLE element on client-side and keep the markup to the fixed width, or use DIV elements instead of the table.

Another option is to use the ClientExportManager, which allows you to export to PDF on client-side only:

Best Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
david
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
david
Top achievements
Rank 1
Share this question
or