ASP.NET rdlc with external images not displaying images in PDF

I use Microsoft ReportViewer, which comes with ASP.NET and has a report parameter that should set the value (path) of the image in my report. I provide the path as the full URL right now, starting with http: //, but also tried this as the relative path of the application, the path to the site, etc., And for some reason the image always displays as red X when it is exported to pdf. I simply create an instance of the control in the code, setting the properties and exporting directly to the response stream so that it loads.

I'm just not sure if the problem might be due to the image not appearing, so if anyone has any ideas please let me know.

UPDATE 1

I decided that I could embed the image with the URL if it is on my public web server, but when I run in localhost, the image will not be inserted. I have confirmed for localhost that if I paste the same URL into my browser, the image will open normally. As far as I know, I do not have a proxy. So I can get around my problem, but I still don't understand what the problem is with localhost.

UPDATE 2

I forgot to note that when the image URL is opened from the browser, it works fine.

+7
reportviewer rdlc
source share
7 answers

PDF cannot contain a link to an external image (at least from my understanding). For an image to appear in a PDF file, it must be embedded in the document. Therefore, in order to use an external image, your application must receive the image and save it in a document. The report viewer will try to do this for you.

Two possible answers:

First , for your application to pack the image into a PDF file, it must be able to extract the image from the URL you specify. If this URL is located behind the proxy server (from the point of view of your application server) and / or requires access to credentials, this will cause a problem with setting the default report viewer.

If a proxy server is a problem, see the settings in your web.config, which you can add below. You may also need to provide network credentials so that your application can authenticate with a proxy. There are many ways to solve this problem, but one of the easiest is to run the application as a service account in your domain, which has the rights to go through your proxy. You can verify this by starting the site as temporary (it should be temporary because it is a terrible security practice).

The image you use may require access to credentials (try raising the image in Firefox with empty cookies and see if you need credentials to access it). If this requires Windows authentication, the same proxy protection solution can be used to authenticate with the remote image. If this requires a different form of authentication, you might be better off loading and embedding the image in your project.

You can also load the image using other means in the code and convert it to an array of bytes for inclusion in the report. There are many examples on the Internet, including a stack overflow here .

Second , take a look at the following page:

http://msdn.microsoft.com/en-us/library/ms251715%28VS.80%29.aspx

Using external images in the ReportViewer Report is not enabled by default. To use an external image, you must set the EnableExternalImages property in your code. Depending on your network configuration, you may also need to bypass the proxy server settings to allow an external image. You can add the following settings for the Web.config file to bypass the local proxy. When changing the Web.config file, be sure to specify the name of the proxy server that is used on your network:

<system.net> <defaultProxy> <proxy usesystemdefault = "false" bypassonlocal = "true" proxyaddress = "http://< proxyservername >:80/" /> <defaultProxy> </system.net> 

We hope that one or both of them will help.

Jerry

+14
source share

When transferring external image file names to ReportViewer parameters, pass the following format: file: // C: \ app \ images \ pic.jpg. Something else does not work well when deployed.

+3
source share

Ok, so this is our decision. The web server did not recognize its own DNS name as a URL, so we had to edit the Hosts file in the C: \ Windows \ System32 \ drivers \ etc folder and add the host name as localhost. The line we added to the file was:

ourserver.ourdomain.com 127.0.0.1

+2
source share

Have you tried the usual file path (c: /temp/somefile.bmp)? A Reporting Services local report reads a file from disk and inserts it into a pdf file. Verify that the application pool identifier in IIS has read permission in the image file.

We do this, and our images are placed in the img folder under the website, along with the rest of the website images. We avoid hard-coding paths using Server.MapPath (relative path).

Hope this helps

+1
source share
  • Can a report viewer get an image from a relative url? I have never used it, so it’s best to check this assumption.
  • Have you tried using Html.Content () to set the url? Whenever I have problems with my URLs because I have not used this to create the correct URL for the submission.
0
source share

I don’t think that Adobe Reader (or maybe the PDF specification itself?) Allows downloading external content for security reasons. I vaguely remember that I had a similar problem that had nothing to do with reporting services (I dynamically generated PDF files and used variable logos and had to implement them).

0
source share

I fixed my problem with this:

 //For local relative paths string imgUrl = new Uri(HttpContext.Current.Server.MapPath("~/images/mylocalimage.jpg")).AbsoluteUri; // OR // For complete URLs { ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; // This allows reportViewer to download image from url string imgUrl = /* Your image URL ("http://") */; } //Then pass imgUrl parameter as external source of your image. 
0
source share

All Articles