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

RadGrid PDF Export - Image Size Issue

2 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 18 Jul 2012, 02:09 AM
Hi guys,

Loving the PDF export functionality so far. Although I'm struggling with an issue with image size when exported to PDF.

My radgrid displays some jpg and gif images which are quite large, so I'm resizing them dynamically with OnItemDataBound.
This all works fine on the page, but when I export the radgrid to PDF, the images seem to lose their dimensions i.e. they display at their original size in the PDF.

Is there a way to resize them for PDF export? I've been using the ItemCreated event to modify cell sizes etc, but can't work out how to do the same with images.

Thanks,
Andrew

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jul 2012, 01:58 PM
Hello,

Please try with below code snippet.
<telerik:GridTemplateColumn>
                   <ItemTemplate>
                       <asp:Image ID="img1" runat="server" ImageUrl="~/images/jayesh.jpg" Width="20px" Height="20px" />
                   </ItemTemplate>
                   </telerik:GridTemplateColumn>

protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.ExportToPdfCommandName)
        {
            foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
            {
                (item.FindControl("img1") as Image).Height = Unit.Pixel(300);
                (item.FindControl("img1") as Image).Width = Unit.Pixel(300);
            }
        }
}

OR

protected void RadGrid2_PdfExporting(object sender, GridPdfExportingArgs e)
   {
       e.RawHTML = e.RawHTML.Replace("<img", "<img style=\"height:20px;width:20px;\" ");
   }


Thanks,
Jayesh Goyani
0
Andrew
Top achievements
Rank 1
answered on 26 Jul 2012, 08:10 AM
Thanks for the info Jayesh.

This code does work, however I couldn't get it to work.
I then noticed it was because I was resizing the image on ItemDataBound. I put in a check for whether or not I'm exporting to PDF & resize the image appropriately at that time.

Thanks!
Andrew
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Andrew
Top achievements
Rank 1
Share this question
or