PDFsharp can't find image (image not found)


PDFsharp can't find image (image not found)



I am using PDFsharp in an ASP.NET MVC application. I want to add an image but no matter what directory I put it in, it can't seem to find it. I have code like this as I am trying to copy the sample application

 Section section = document.AddSection();  Image image13 = section.AddImage("../../images/logo.png"); 

No matter what directory I put this image in, when the PDF gets generated, I see an error on the PDF saying "Image not found"

Has anyone else seen this issue?


Master ASP.NET MVC

1:

How do I convert DateTime format to ShortDateString in Jquery?
It might be looking for a full path?. Why is VS2010 in ASP.NET MVC2 giving me the wrong JQuery intellisense? Try . Unit testing with EF4 “Code First” and Repository
Image image13 = section.AddImage(Server.MapPath("~/images/logo.png")); 
Passing nested arrays to asp.net mvc using jQuery's $.ajaxHow to fake Http post?

2:

MVC Ajax PartialViews not firing Javascript - should I use Spark?
i am using pdfsharp in a asp.net mvc application.. Grab data from table, join string from two columns, display in MVC selectList
BTW: You are not using PDFsharp, you are using MigraDoc.. MigraDoc searches the images relative to the current directory. ASPX pages are compiled to and are executed from a temporary directory, not from the project directory. Therefore relative paths will not job as expected.. Assembly.CodeBase might guidance to locate the images; Assembly.Location indicates the temporary directory.. Assembly.CodeBase must be used in code this is shared between ASP.NET and .NET. Server.MapPath must also be used (as suggested by Marko), although it works in ASP.NET only..

3:

The MigraDoc Document object has an ImagePath property this allows you to specify the directories this will be searched for images (separate multiple directories with semikola).. If images must be found relative to the location of the assembly, then Assembly.CodeBase must be used to locate the assembly (as mentioned in my earlier answer)..

4:

Old thread although might come in handy for any one. This worked for me:.
Document doc = new Document(); doc.ImagePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", ""); 
I then set my image to copy always and added it with its relative path by bin directory in my Web project..


56 out of 100 based on 26 user ratings 386 reviews

#