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

Radgrid PDF export pictures not working

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laurie
Top achievements
Rank 1
Laurie asked on 07 Dec 2015, 06:06 PM

I'm trying to export a radgrid to a pdf with pictures that are embedded inside of it.  I currently have a radgrid, and one of the columns is using a grid template column with a radlistview control, and a binary image control inside of that.  Everything renders ok, but the pdfexport won't seem to export images.  My goal with the grid template column is to load a list of photo's in each cell, but also be able to export this to a pdf.

 

protected void QuesGrd_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
 
        using (var db = new IASurvey.Core.IADbContext())
        {
 
            GridDataItem item = (GridDataItem)e.Item;
            Guid AnswerId = Guid.Parse(item["ansId"].Text);
            HyperLink link = (HyperLink)item["link"].Controls[0];
            var answerphoto = db.Photos.Where(p => p.PhotoAnswerId == AnswerId);
            var answerlist = answerphoto.ToList();
            RadListView lv = item.FindControl("RadListView1") as RadListView;
            if (lv != null)
            {
                lv.DataSource = answerlist;
            }
 
            if (answerphoto.Any())
            {
                link.Text = "View/Print Photo(s)";
                string url = "~/PhotoOpen.aspx?AnswerId=" + AnswerId;
                link.Target = "_blank";
                link.NavigateUrl = (url);
                //link.Attributes.Add("onclick", "javascript:window.resizeTo(600,600);");
            }
            else
            {
                link.Text = "No Photos";
            }
        }
 
    }
}

protected void QuesGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        foreach (GridHeaderItem item in QuesGrid.MasterTableView.GetItems(GridItemType.Header))
        {
 
            item.Style["font-size"] = "15pt";
            foreach (TableCell cell in item.Cells)
            {
                cell.Style["font-size"] = "6pt";
                cell.Style["vertical-align"] = "middle";
            }
        }
        isPdfExport = true;
        ConfigureExport();
    }
}
 
 
protected void QuesGrid_ItemCreated(object sender, GridItemEventArgs e)
{
    if (isPdfExport && e.Item is GridHeaderItem)
    {
        GridHeaderItem headerItem = (GridHeaderItem)e.Item;
        headerItem.Style["font-size"] = "16pt";
        headerItem.Style["color"] = "#ffffff";
        headerItem.Style["background-color"] = "#BD0034";
        headerItem.Style["height"] = "40px";
        headerItem.Style["horizontal-align"] = "center";
        headerItem.Style["vertical-align"] = "middle";
        headerItem.Style["font-weight"] = "bold";
        headerItem.Style["text-align"] = "center";
 
        foreach (TableCell cell in headerItem.Cells)
        {
 
        }
    }
}
 
public void ConfigureExport()
{
    QuesGrid.ExportSettings.IgnorePaging = true;
    QuesGrid.ExportSettings.ExportOnlyData = true;
    QuesGrid.ExportSettings.OpenInNewWindow = true;
    QuesGrid.ExportSettings.UseItemStyles = true;
    QuesGrid.ClientSettings.Scrolling.AllowScroll = false;
    QuesGrid.ExportSettings.FileName = "Survey (" + DateTime.Now + ")";
}

 

<telerik:GridTemplateColumn UniqueName="photo" HeaderText="Photo(s)"
     <ItemTemplate
     <telerik:RadListView ID="RadListView1" runat="server" DataMember="Binary" GroupItemCount="10" PageSize="10">
        <ItemTemplate>
            <telerik:RadBinaryImage ID="RadBinaryImage1" runat="server" DataValue='<%#Eval("Image") %>' Width="200px" Height="200px" ResizeMode="Fit" />
            <p class="pagebreakhere">
                 
        </ItemTemplate>
 
        </telerik:RadListView>
    </ItemTemplate
</telerik:GridTemplateColumn>

2 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 10 Dec 2015, 09:01 AM
Hello Laurie,

I already answered the support ticket that you have opened but I will post the reply here as well if some other customers have the same inquiry.

Keep in mind that our PDF engine can export all images nevertheless whether they use an absolute or relative path, but binary image will not be exported. If you try to export a binary image the export document will be created but it will not contains the image.
Nevertheless, you can use ClientExportManager to export the grid to pdf and in such case the document will contains the binary images.


Regards,
Kostadin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
RJ
Top achievements
Rank 1
answered on 25 Apr 2016, 06:55 AM

Hi Kostadin,

 

Currently I'm using export to PDF with Header image. It works fine w/o any issue, though at some point, a client imported their logo with transparent background which resulted to black background when exported to PDF. Any workaround I can do?

Here's my code:

Grid1.ExportSettings.Pdf.PageHeader.LeftCell.Text = "<img src=""myLogo"" alt=""Company Logo"" align=""right"" style=""height: 64px; width: auto; "" />"

 

Thanks in advance,

Rj

 

 

Tags
Grid
Asked by
Laurie
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
RJ
Top achievements
Rank 1
Share this question
or