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

RadGrid: add Image to PDF Export

1 Answer 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mayank Tyagi
Top achievements
Rank 1
Mayank Tyagi asked on 30 Sep 2011, 08:35 PM
I am using a class that is derived from the RadGrid...

    public

 

 

class RadGridExport : RadGrid

We are using the native PDF export features of the RadGrid control.  I would like to be able to insert an image (corporate logo) into the beginning of the pdf file (above the data table data).

I found the OnPDFExporting() event and decided to override it and thus access the RawHTML stream. 
I then attempted to add an image to the HTML via the <img> element:

 

 

 

 

 

 

 

protected override void OnPdfExporting(GridPdfExportingArgs e)

 

{

 

 

 

 

base.OnPdfExporting(e);

 

 

 

string newHTML = string.Empty;

 

 

 

string addHTML = string.Empty;

 

newHTML = e.RawHTML;

 

 

//THIS WORKS

 

addHTML =

 

@"<img alt='test' src='../images/corp_logo.gif'/>";

 

 

 

//THIS DOES NOT WORK (where URL is correct and resolvable)

 

addHTML =

 

@"<img alt='test' src='https://mycorp.net/pages/Custom/Images/corp_logo.gif'/>";

 

newHTML = addHTML + newHTML;

e.RawHTML = newHTML;

}

 

 

The issue that I am running into is that the above technique will work as long as I am using a relative path that resolves within the directory structure of the web application / virtual directory.

However, if I used an absolute path (via http:/ or file:/ or even embedded by data:) that I get an error similar to:

"System.SystemException: Error while creating area : Encountered web exception while fetching image from file:///C:/WORKING/MyProject/MyProject.Controls/Test/https://mycorp.net/pages/Custom/Images/corp_logo.gif: The given path's format is not supported."

Even though I have manually coded the src attribute with a absolute path to a URL... the RadGrid appears to resolve to my web apps directory structure.

Is there any way that I can avoid this behavior and have the src attribute work against an absolute?

Or is there another technique or method recommended for adding an image to a PDF file that is being exported?

Thanks,
M.T.



1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Oct 2011, 05:37 AM
Hello Mayank,

I have found the following forum which discussed the similar issue.
Export images to pdf.

Thanks,
Shinu.
Tags
Grid
Asked by
Mayank Tyagi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or