Export to PDF

Thread is closed for posting
4 posts, 0 answers
  1. Ananth
    Ananth avatar
    10 posts
    Member since:
    Jul 2012

    Posted 07 Jul 2012 Link to this post

    Hi,

    I am new to telerik. I am using ASP.NET AJAX Q1 2012 version. Now I have 3 radchart(one bar chart and 2 pie chart) and 1 radgrid. Now I want to export all these four charts into a single pdf file. Is possible? Any one help me for this please.
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 11 Jul 2012 Link to this post

    Hi Ananth,

    The RadChart arrives as a static image on the client. We do not support out-of-the-box export to pdf because you can export it wpf just as any other image, but you can check this code-library where this is demonstrated.

    Regards,
    Petar Marchev
    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ananth
    Ananth avatar
    10 posts
    Member since:
    Jul 2012

    Posted 13 Jul 2012 Link to this post

    Hi,

    Thanks for your reply. Your reply some what helps to me, but it's not completely solve my problem.

    The following are the code used in my aspx page.

    Below code look like the attachment, Chart.png.

    <telerik:RadGrid ID="rgTestingGrid" runat="server" OnNeedDataSource="rgTestingGrid_NeedDataSource"
            ShowHeader="false" Width="100%" OnItemCommand="rgTestingGrid_ItemCommand" OnItemDataBound="rgTestingGrid_ItemDataBound">
            <ExportSettings ExportOnlyData="false" IgnorePaging="true" OpenInNewWindow="true">
            </ExportSettings>
            <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="Top" BorderStyle="None">
                <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToExcelButton="false"
                    ShowExportToPdfButton="true" ShowExportToWordButton="false" ShowRefreshButton="false" />
                <Columns>
                    <telerik:GridTemplateColumn UniqueName="ChartCol">
                        <ItemTemplate>
                            <table cellpadding="0" cellspacing="0" border="0">
                                <tr>
                                    <td align="left">
                                        <telerik:RadChart ID="RadChart1" SkinsOverrideStyles="true" runat="server" Width="500">
                                            <PlotArea>
                                                <XAxis MaxValue="5" MinValue="1" Step="1">
                                                </XAxis>
                                                <YAxis MaxValue="3" Step="0.5" AxisMode="Extended">
                                                </YAxis>
                                                <YAxis2 MaxValue="5" MinValue="1" Step="1">
                                                </YAxis2>
                                            </PlotArea>
                                            <Series>
                                                <telerik:ChartSeries Name="Series 1">
                                                    <Appearance>
                                                        <FillStyle MainColor="Red">
                                                        </FillStyle>
                                                    </Appearance>
                                                    <Items>
                                                        <telerik:ChartSeriesItem YValue="1" Name="Item 1">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="2" Name="Item 2">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="1" Name="Item 3">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="3" Name="Item 4">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="2" Name="Item 5">
                                                        </telerik:ChartSeriesItem>
                                                    </Items>
                                                </telerik:ChartSeries>
                                                <telerik:ChartSeries Name="Series 2">
                                                    <Appearance>
                                                        <FillStyle MainColor="Blue">
                                                        </FillStyle>
                                                    </Appearance>
                                                    <Items>
                                                        <telerik:ChartSeriesItem YValue="3" Name="Item 1">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="1" Name="Item 2">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="3" Name="Item 3">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="1" Name="Item 4">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="2" Name="Item 5">
                                                        </telerik:ChartSeriesItem>
                                                    </Items>
                                                </telerik:ChartSeries>
                                            </Series>
                                        </telerik:RadChart>
                                    </td>
                                    <td align="left" style="width: 2%">
                                          
                                    </td>
                                    <td align="left" style="width: 49%">
                                        <telerik:RadChart ID="RadChart2" runat="server" SkinsOverrideStyles="true" Width="500px">
                                            <PlotArea>
                                                <XAxis MaxValue="5" MinValue="1" Step="1">
                                                </XAxis>
                                                <YAxis MaxValue="25" Step="5">
                                                </YAxis>
                                                <YAxis2 MaxValue="5" MinValue="1" Step="1">
                                                </YAxis2>
                                            </PlotArea>
                                            <Series>
                                                <telerik:ChartSeries Name="Series 1" Type="Pie">
                                                    <Items>
                                                        <telerik:ChartSeriesItem YValue="23" Name="Item 1">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="20" Name="Item 2">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="24" Name="Item 3">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="19" Name="Item 4">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="25" Name="Item 5">
                                                        </telerik:ChartSeriesItem>
                                                    </Items>
                                                </telerik:ChartSeries>
                                            </Series>
                                        </telerik:RadChart>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                          
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left">
                                        <telerik:RadGrid ID="rgTenMostPopularJobs" runat="server" CssClass="RadGrid" ShowHeader="true"
                                            ShowFooter="false" GridLines="none" Skin="Office2007" Width="500" Height="300"
                                            BorderWidth="1" AutoGenerateColumns="False" ShowStatusBar="false" DataSourceID="SqlDataSource1"
                                            ClientSettings-Scrolling-AllowScroll="true">
                                            <MasterTableView>
                                                <Columns>
                                                    <telerik:GridBoundColumn DataField="JobCategory" DataType="System.String" FilterControlAltText="Filter Job Category Column"
                                                        HeaderText="Category" ReadOnly="true" SortExpression="JobCategory" UniqueName="JobCategory">
                                                        <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                                        <ItemStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="JobIDApplied" DataType="System.Int32" FilterControlAltText="Filter Job ID Applied Column"
                                                        HeaderText="Job ID" ReadOnly="true" SortExpression="JobIDApplied" UniqueName="JobIDApplied">
                                                        <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                                        <ItemStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridBoundColumn DataField="TOTAL" DataType="System.Int32" FilterControlAltText="Filter No. of Applies Column"
                                                        HeaderText="No. of Applies" ReadOnly="true" SortExpression="TOTAL" UniqueName="TOTAL">
                                                        <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                                        <ItemStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                                                    </telerik:GridBoundColumn>
                                                </Columns>
                                            </MasterTableView>
                                        </telerik:RadGrid>
                                    </td>
                                    <td align="left" style="width: 2%">
                                          
                                    </td>
                                    <td align="left" style="width: 49%">
                                        <telerik:RadChart ID="RadChart3" runat="server" SkinsOverrideStyles="true" Width="500px">
                                            <PlotArea>
                                                <XAxis MaxValue="5" MinValue="1" Step="1">
                                                </XAxis>
                                                <YAxis MaxValue="25" Step="5">
                                                </YAxis>
                                                <YAxis2 MaxValue="5" MinValue="1" Step="1">
                                                </YAxis2>
                                            </PlotArea>
                                            <Series>
                                                <telerik:ChartSeries Name="Series 1" Type="Pie">
                                                    <Items>
                                                        <telerik:ChartSeriesItem YValue="23" Name="Item 1">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="20" Name="Item 2">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="24" Name="Item 3">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="19" Name="Item 4">
                                                        </telerik:ChartSeriesItem>
                                                        <telerik:ChartSeriesItem YValue="25" Name="Item 5">
                                                        </telerik:ChartSeriesItem>
                                                    </Items>
                                                </telerik:ChartSeries>
                                            </Series>
                                        </telerik:RadChart>
                                    </td>
                                </tr>
                            </table>
                            <asp:Image ID="Image1" runat="server" Visible="false" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

    My .cs code look like this

    protected void rgTestingGrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                DataTable dtTest = new DataTable();
                dtTest.Columns.Add("Chart");
                DataRow drTest;
     
                for (int i = 0; i < 1; i++)
                {
                    drTest = dtTest.NewRow();
                    drTest["Chart"] = "";
                    dtTest.Rows.Add(drTest);
                }
     
                rgTestingGrid.DataSource = dtTest;
            }
     
            protected void rgTestingGrid_ItemCommand(object sender, GridCommandEventArgs e)
            {
                if (e.CommandName == RadGrid.ExportToPdfCommandName)
                    isExport = true;
                else if (e.CommandName == RadGrid.ExportToExcelCommandName)
                    isExport = true;
                else if (e.CommandName == RadGrid.ExportToWordCommandName)
                    isExport = true;
            }
     
            protected void rgTestingGrid_ItemDataBound(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridDataItem)
                {
                    System.Web.UI.WebControls.Image img1 = e.Item.FindControl("Image1") as System.Web.UI.WebControls.Image;
                    string fileName = String.Format("~/ChartImage{0}.png", e.Item.ItemIndex);
                    img1.ImageUrl = fileName;
     
                    if (!isExport)
                    {
                        RadChart rc1 = e.Item.FindControl("RadChart1") as RadChart;
                        rc1.Save(Server.MapPath(fileName), System.Drawing.Imaging.ImageFormat.Png);
                        img1.ImageUrl = fileName;
                    }
                    else
                        img1.Visible = true;
                }
            }

    Here, I can able to export the only one chart to pdf from the above charts, I want to export the whole grid in to single pdf.

    How can I do that?

    Thanks.
  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 18 Jul 2012 Link to this post

    Hi Ananth,

    I have attached a modified version of the project to demonstrate one possible solution for this. You need to have different asp:Image elements for each chart. 

    Kind regards,
    Petar Marchev
    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.
Back to Top