Rad Grid - PDF Export Issues

11 posts, 0 answers
  1. Vivek
    Vivek avatar
    38 posts
    Member since:
    Mar 2013

    Posted 17 Apr 2013 Link to this post

    Hi,

    I'm facing problem with rad grid pdf export where after exporting to pdf, data is completely misaligned. Not sure if the table format I'm using inside the item template causing the issue.

    <telerik:GridTemplateColumn UniqueName="Symbol">
                        <HeaderTemplate>
                            <asp:Label ID="labelHSymbol" runat="server" Text="Symbol"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelSymbol" runat="server" Text='<%# Bind("Symbol") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>

    If you see the code above, I'm using three rows table format where data is present only for third row, other two rows are empty. During PDF export, third row data is getting shifted to first row and finally that is creating complete misalignment in PDF file.

    I tried fixing this alignment issues in OnPDFExporting Event but it didn't work in this scenario, pasted the code below -
    Approach-1:
    protected void TestGrid_PDFExporting(object sender, GridPdfExportingArgs e)
            {
                foreach (GridHeaderItem headerItem in gridIP.MasterTableView.GetItems(GridItemType.Header))
                {
                    headerItem.Style["background-color"] = "Gray";
                }
            }
     
    Approach-2:
      protected void TestGrid_PDFExporting(object sender, GridPdfExportingArgs e)
            {
                foreach (GridHeaderItem headerItem in gridIP.MasterTableView.GetItems(GridItemType.Header))
                {
                    foreach (TableCell cell in headerItem.Cells)
                    {
                        cell.Style["color"] = "#FF00FF";
                    }
                }
            }

    Please help me to investigate this issue, I'm pasting the entire piece of code below -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    namespace PDFXLDownload
    {
        public class MyTestEntity
        {
            public string InvName { get; set; }
            public string ShortName { get; set; }
            public string Status { get; set; }
            public string Symbol { get; set; }
            public string MSRating { get; set; }
            public string NERatio { get; set; }
            public string GERatio { get; set; }
            public string OneQ { get; set; }
            public string YT { get; set; }
            public string OneY { get; set; }
            public string ThreeY { get; set; }
            public string FiveY { get; set; }
            public string TenY { get; set; }
            public string ThreeYR { get; set; }
     
            public static List<MyTestEntity> GetInvestmentPerformanceData()
            {
                List<MyTestEntity> investments = new List<MyTestEntity>
                {
                    new MyTestEntity
                    
                        InvName = "Test Inv Name 1", ShortName="IA-RT", Status="A",
                        Symbol = "N/A", MSRating="2", NERatio="0.46", GERatio="0.46",
                        OneQ="00.00%", YT="00.00%", OneY="00.00%", ThreeY="00.00%", FiveY="00.00%",
                        TenY="00.00%", ThreeYR="00.00%"
                    },
                     new MyTestEntity
                    
                        InvName = "Test Inv Name 2", ShortName="IA-YE", Status="C",
                        Symbol = "N/A", MSRating="2", NERatio="0.46", GERatio="0.46",
                        OneQ="00.00%", YT="00.00%", OneY="00.00%", ThreeY="00.00%", FiveY="00.00%",
                        TenY="00.00%", ThreeYR="00.00%"
                    },
                     new MyTestEntity
                    
                         InvName = "Test Inv Name 3", ShortName="IA-RT", Status="B",
                        Symbol = "N/A", MSRating="3", NERatio="0.46", GERatio="0.46",
                        OneQ="00.00%", YT="00.00%", OneY="00.00%", ThreeY="00.00%", FiveY="00.00%",
                        TenY="00.00%", ThreeYR="00.00%"
                    },
                     new MyTestEntity
                    
                        InvName = "Test Inv Name 4", ShortName="IA-RT", Status="D",
                        Symbol = "N/A", MSRating="4", NERatio="0.46", GERatio="0.46",
                        OneQ="00.00%", YT="00.00%", OneY="00.00%", ThreeY="00.00%", FiveY="00.00%",
                        TenY="00.00%", ThreeYR="00.00%"
                    }
                };
                return investments;
            }
        }
    }

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PDFXLDownload.aspx.cs"
        Inherits="PDFXLDownload.PDFXLDownload" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
        <link href="Styles/Site.css" rel="stylesheet" type="text/css" />
        <link href="Grid.Default.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableScriptCombine="false">
        </telerik:RadScriptManager>
        <telerik:RadGrid runat="server" ID="gridIP" EnableEmbeddedSkins="false" GridLines="None"
            ShowFooter="false" AllowFilteringByColumn="false" AllowSorting="false" ShowGroupPanel="false"
            AllowPaging="false" OnPdfExporting="TestGrid_PDFExporting">
            <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Bottom">
                <Columns>
                    <telerik:GridTemplateColumn UniqueName="InvName">
                        <HeaderTemplate>
                            <asp:Label ID="labelHInvName" runat="server" Text="Inv Name"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="200px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                        <asp:Label ID="label1" runat="server" Text="AC Test Data One"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="label2" runat="server" Text="AC Test Data Two"></asp:Label>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelInvName" runat="server" Text='<%# Bind("InvName") %>'></asp:Label>  
                                        <asp:Label ID="labelShortName" runat="server" Text='<%# Bind("ShortName") %>'></asp:Label>  
                                        <asp:Label ID="labelStatus" runat="server" CssClass="FundStatus" Text='<%# Bind("Status") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="Symbol">
                        <HeaderTemplate>
                            <asp:Label ID="labelHSymbol" runat="server" Text="Symbol"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelSymbol" runat="server" Text='<%# Bind("Symbol") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="MSRating">
                        <HeaderTemplate>
                            <asp:Label ID="labelHMSRating" runat="server" Text="MSRating"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelMSRating" runat="server" Text='<%# Bind("MSRating") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="NERatio">
                        <HeaderTemplate>
                            <asp:Label ID="labelHNERatio" runat="server" Text="NERatio"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelNERatio" runat="server" Text='<%# Bind("NERatio") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="GERatio">
                        <HeaderTemplate>
                            <asp:Label ID="labelHGERatio" runat="server" Text="GERatio"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelGERatio" runat="server" Text='<%# Bind("GERatio") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="OneQ">
                        <HeaderTemplate>
                            <asp:Label ID="labelHOneQ" runat="server" Text="OneQ"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelOneQ" runat="server" Text='<%# Bind("OneQ") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="YT">
                        <HeaderTemplate>
                            <asp:Label ID="labelHYT" runat="server" Text="YTenure"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelYT" runat="server" Text='<%# Bind("YT") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="OneY">
                        <HeaderTemplate>
                            <asp:Label ID="labelHOneY" runat="server" Text="OneY"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelOneY" runat="server" Text='<%# Bind("OneY") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="ThreeY">
                        <HeaderTemplate>
                            <asp:Label ID="labelHThreeY" runat="server" Text="ThreeY"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelThreeY" runat="server" Text='<%# Bind("ThreeY") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="FiveY">
                        <HeaderTemplate>
                            <asp:Label ID="labelHFiveY" runat="server" Text="FiveY"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelFiveY" runat="server" Text='<%# Bind("FiveY") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="TenY">
                        <HeaderTemplate>
                            <asp:Label ID="labelHTenY" runat="server" Text="TenY"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelTenY" runat="server" Text='<%# Bind("TenY") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn UniqueName="ThreeYR">
                        <HeaderTemplate>
                            <asp:Label ID="labelHThreeYR" runat="server" Text="ThreeYR"></asp:Label>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <table width="70px">
                                <colgroup>
                                    <col />
                                </colgroup>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:Label ID="labelThreeYR" runat="server" Text='<%# Bind("ThreeYR") %>'></asp:Label>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <CommandItemStyle HorizontalAlign="Left" Wrap="true" Width="100%" />
                <CommandItemTemplate>
                    <asp:Label ID="lblText" runat="server" Visible="false" Width="100%"></asp:Label>
                </CommandItemTemplate>
            </MasterTableView>
        </telerik:RadGrid>
        <asp:Button ID="DownloadPDFButton" runat="server" OnClick="DownloadPDFButton_Click"
            Text="Download PDF" Width="184px" />
        <asp:Button ID="DownloadXLButton" runat="server" OnClick="DownloadXLButton_Click"
            Text="Download Exel" Width="157px" />
        </form>
    </body>
    </html>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.IO;
     
    namespace PDFXLDownload
    {
        public partial class PDFXLDownload : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                gridIP.DataSource = MyTestEntity.GetInvestmentPerformanceData();
                gridIP.DataBind();
            }
     
            protected void TestGrid_PDFExporting(object sender, GridPdfExportingArgs e)
            {
                string rowHtml = e.RawHTML.ToString();
     
                e.RawHTML = rowHtml.Replace("<td></td>", "<td style=\"height:20px\"></td>");
     
            }
     
            protected void DownloadPDFButton_Click(object sender, EventArgs e)
            {
                gridIP.ExportSettings.OpenInNewWindow = true;
     
                gridIP.ExportSettings.FileName = "PDFExportDemo";
                gridIP.ExportSettings.ExportOnlyData = false;
     
                //Landscape
                gridIP.ExportSettings.Pdf.PageHeight = Unit.Parse("10in");
                gridIP.ExportSettings.Pdf.PageWidth = Unit.Parse("16in");
     
                //// 1/2 inch margins
                gridIP.ExportSettings.Pdf.PageLeftMargin = Unit.Parse("1in");
                gridIP.ExportSettings.Pdf.PageRightMargin = Unit.Parse("1in");
                gridIP.ExportSettings.Pdf.PageTopMargin = Unit.Parse("1in");
                gridIP.ExportSettings.Pdf.PageBottomMargin = Unit.Parse("1in");                     
     
                gridIP.ExportSettings.FileName = "Test Pdf File";
     
                gridIP.MasterTableView.Columns.FindByUniqueName("InvName").HeaderStyle.Width = Unit.Pixel(200);
     
                gridIP.MasterTableView.ExportToPdf();
            }    
     
            protected void DownloadXLButton_Click(object sender, EventArgs e)
            {
                gridIP.ExportSettings.OpenInNewWindow = true;
                 
                gridIP.ExportSettings.FileName = "MyTestEntity";
                gridIP.ExportSettings.Excel.FileExtension = "xls";
                 
                gridIP.MasterTableView.ExportToExcel();
            }
     
            
        }   
    }

                      
  2. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 22 Apr 2013 Link to this post

    Hello Vivek,

    Could you please try the following approach:
    protected void TestGrid_PDFExporting(object sender, GridPdfExportingArgs e)
        {
            string rowHtml = e.RawHTML.ToString();
            rowHtml = rowHtml.Replace("<th scope=\"col\">", "<th scope=\"col\" style=\"text-align:center;\">");
            e.RawHTML = rowHtml.Replace("<td>", "<td style=\"height:20px; text-align:center;\">");       
        }

    I noticed that the way you are trying to replace the <td> tags does not work properly.

    All the best,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Vivek
    Vivek avatar
    38 posts
    Member since:
    Mar 2013

    Posted 23 Apr 2013 Link to this post

    Thanks Kostadin, your solution works fine in pdf export but similar issue persist in excel export.

    Please let me know what changes has to be done to get excel data properly aligned.

    Is there any event to make final changes in generated excel.

  4. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 26 Apr 2013 Link to this post

    Hello Vivek,

    You could use the same approach to style the excel file. Note that you have to hook OnGridExporting event handler and modify the ExportOutput. For instance.
    protected void RadGrid1_GridExporting(object sender, Telerik.Web.UI.GridExportingArgs e)
        {
            string rowHtml = e.ExportOutput.ToString();
            rowHtml = rowHtml.Replace("<th scope=\"col\">", "<th scope=\"col\" style=\"text-align:center;\">");
            e.ExportOutput = rowHtml.Replace("<td>", "<td style=\"height:20px; text-align:center;\">");      
        }


    Regards,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Vivek
    Vivek avatar
    38 posts
    Member since:
    Mar 2013

    Posted 16 May 2013 Link to this post

    Hi Kostadin,

    As suggested earlier, I tried using the "OnGridExporting" but it just give me the corrupted output which I can't really modify, pasting the corrupted ExportOutput below which I got from this event handler.

    %PDF-1.3 %âãÏÓ 4 0 obj << /Producer (ò\r ²JòbÙ \n$¬‘Ž©ÆÏc–Ïí÷œ+O`4}ÅÄ€Ãîy*¤’Áy&õø¶¢œ<l²w}‚㚸—-+!3EÍO‡ÎjÒDéÿ\(C´r©ºèçõf‰–á J«Eª«ì’) /Creator (ò\r ²Jòb×"‹±Æ©½Šy‘Òò£Ž6&s}FŽ×‡©!1ëÝï#) /CreationDate (âRUç ¨9ÂmYtcÌí–¹Ê) >> endobj 5 0 obj << /V 1 /Length 40 /O ( UÇVÇ.×`Ž–¬­DzÓ-Ïõƒ#_mÑ_í}«g) /P -60 /R 2 /Filter /Standard /U (РÉq®v­ v´¨PPØ›d_[B¾ÆÓweB´) >> endobj 6 0 obj << /Length 1158 /Filter null >> stream ™R˜ÐÁMŽpø–~¦[è…GþWk‘jƒ·Ž½Ç¿Í íÕZÑà˜ÅÚi_¥f |ŒïSK¿– “Ä"Ô€*¾q­ÔBnñª4 ’îÄá¡nÃ&OÒ>ÇüA'²Ïém©§–~Œ|Ð ¯g ÖÈ‘'*N÷ýà-ñÎ7 &‹VÌ{¾ˆ«#IJŽ±5f’åòò÷”{„~ » dy€Šµ%d®ÀҏyÍ@(íž±5 Jê1ØÜÜ£EbaJbŽ÷î2w±$z—>€rÙ£µKêZ„ã ´÷|³”0ÙŠ!ZYÂ¥9#úû#éCLïdY|V™Žy¾R.ùõÇ¢N^ù±¤ú±ºöªbFÛˆQgKá¼wêuOÁ®•"³üqÓÛÅGŸ·Q^½§Ä}y `Î<ÐÑái£€îOí~BóŸöï] ŸË‹—P ˜‹ƒ–é4u¼uÍzœ³ØCŽœSv6«ÔBO±h/e8È}~Á(Á)WµàíN\Ð¥2y%¦êX€zF£„ÊFô[­_ñip‚~'ò®ËjpôIýŽ|6l@Ã\inTl¬+¼|¡§‹… õŽ‚ácfP¤º÷¢NðÄH=pÓ¦¯Á!‘‘±}r «Noî˜LÞAÂ7+Q±¸ı@sÔî Ãey`Ø@m\4£áGy0™å•î(aØ,QG%ÊÇMÀÎ`¢èiŽeÓÞW ¸BŒ¸òß½€½Ÿ

    Not sure why I'm getting this corrupted exported output, please let me know what's the solution for this.



  6. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 21 May 2013 Link to this post

    Hello Vivek,

    What I was trying to said is that when export to excel is fired you have to modify the table OnGridExporting event handler. If you are trying to modify the table when exporting to PDF you have to hook OnPDFExporting event handler. You could create a boolean variable which indicates which export format is currently exporting. For instance.
    protected void RadGrid1_GridExporting(object sender, Telerik.Web.UI.GridExportingArgs e)
    {
        if (isExportToExcel)
        {
            string rowHtml = e.ExportOutput.ToString();
            rowHtml = rowHtml.Replace("<th scope=\"col\">", "<th scope=\"col\" style=\"text-align:center;\">");
            e.ExportOutput = rowHtml.Replace("<td>", "<td style=\"height:20px; text-align:center;\">");    
        }
    }


    Kind regards,
    Kostadin
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 21 May 2013 Link to this post

    Or you could use this.

    protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
       {
         if (e.ExportType == ExportType.Excel)
           {
             // Do Something
           }
         if(e.ExportType == ExportType.Pdf)
          {
          // Do Something
          }
     }
  8. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 24 May 2013 Link to this post

    Hello Mike,

    If you try to modify the raw html when exporting to pdf it have to be done OnPdfExporting event handler, because OnGridExporting event the ExportOutput is binary which could not be modified.

    Regards,
    Kostadin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 24 May 2013 Link to this post

    Kostadin,

    I am trying that and oh so close, but alll that is output in the PDF is HTML source code.  What am I doing wrong here?

    protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
       {     
           StringBuilder customHTML = new StringBuilder();
           customHTML.Append("<table style='font-size: 10px; font-family:Arial Unicode MS;width:500px;'>");
           customHTML.Append("<colgroup><col style='width: 200px; white-space:nowrap;' /><col style='text-align:left;' /></colgroup>");
           customHTML.Append("<tr><td>Name: " + Label3.Text + "</td><td>ID: " + Label4.Text + " </td></tr>");
           customHTML.Append("</table>");
           customHTML.Append("<p></p>");
           e.RawHTML = customHTML + e.RawHTML;
           
           var doc = new Document();
           MemoryStream memoryStream = new MemoryStream();
           PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);
     
           doc.Open();
           doc.Add(new Paragraph("HEADER"));
           doc.Add(new Paragraph(e.RawHTML));
            
           writer.CloseStream = false;
           doc.Close();
           memoryStream.Position = 0;      
     
           // Test Email
           SmtpClient smtpClient = new SmtpClient(Convert.ToString(ConfigurationManager.AppSettings["SERVER_EMAIL"]));
           string authType = "Basic";
           MailMessage email = new MailMessage();
           StringBuilder body = new StringBuilder();
           string emaURL = Convert.ToString(ConfigurationManager.AppSettings["BASE_URL"]);
           email.From = new MailAddress("email1@gmail.com");
           email.CC.Add("email2@gmail.com");
           email.Subject = "Test" + Label1.Text + " - " + Convert.ToString(ConfigurationManager.AppSettings["SERVER_NAME"]) + " - Group " + Label2.Text;
           email.Attachments.Add(new Attachment(memoryStream, "TEST.pdf"));
           email.Body = body.ToString();
           email.IsBodyHtml = true;
           NetworkCredential nc = new NetworkCredential(RijndaelAlgorithm.Decrypt(Convert.ToString(ConfigurationManager.AppSettings["CredentialU"])), RijndaelAlgorithm.Decrypt(Convert.ToString(ConfigurationManager.AppSettings["CredentialP"])));
           smtpClient.Credentials = nc.GetCredential(Convert.ToString(smtpClient), 25, authType);
           smtpClient.Send(email);       
       }
  10. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 29 May 2013 Link to this post

    Hello Mike,

    I am not completely sure what exactly is the issue. Could you please elaborate a little bit more on your scenario? If you are trying to get the rendered html I would suggetst you to use RenderControl().

    Regards,
    Kostadin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  11. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 29 May 2013 Link to this post

    I ended up just making an example for everyone click here
Back to Top