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

Change image in picturebox when exporting to pdf

1 Answer 216 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 01 Apr 2009, 11:57 AM
Hi,
I need to change the image when exporting to pdf because I want the image to be 300 dpi when printing and 72 when viewing on the webpage.
I have tried this with no success:
private void pictureBox1_ItemDataBound(object sender, EventArgs e) 
        { 
            HttpContext context = System.Web.HttpContext.Current; 
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Profit)); 
            if (context != null
                pictureBox1.Value = ((object)resources.GetObject("logo72dpi")); 
            else 
                pictureBox1.Value = ((object)resources.GetObject("logo300dpi")); 
        } 
The report is called Profit and the images is in projects resource file.
Can you help me?

/Mattias

1 Answer, 1 is accepted

Sort by
0
Steve
Telerik team
answered on 02 Apr 2009, 04:31 PM
Hello Mattias,

There are a couple of problems here:
  1. System.Web.HttpContext would never be null when you're in the context of a web page i.e. you're showing the report in a web report viewer. So you need a different check.
  2. You're using the definition picturebox item, when you should be using the processing one when you're in an event. More info is available in this help article.
Here is the code I've tried on my end that is working:

private void pictureBox1_ItemDataBound(object sender, EventArgs e) 
        { 
             
            Processing.PictureBox pic = sender as Processing.PictureBox; 
 
            HttpContext context = System.Web.HttpContext.Current; 
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Testing)); 
            this.bg1 = (Image)resources.GetObject("1"); 
            this.bg2 = (Image)resources.GetObject("2"); 
 
            pic.Image = this.bg1; 
 
            if (context != null
            { 
                string exportFormat = context.Request.QueryString["ExportFormat"]; 
                if ((exportFormat != "MHTML") && (exportFormat != null)) 
                { 
                    pic.Image = this.bg2; 
                } 
            } 
                 
        } 

where bg1 and bg2 are defined images.
Greetings,
Steve
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Mattias
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or