views:

49

answers:

3

i am using pdfsharp in a 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?

A: 

It might be looking for a full path?

Try

Image image13 = section.AddImage(Server.MapPath("~/images/logo.png"));
Marko
A: 

i am using pdfsharp in a asp.net mvc application.

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 work as expected.

Assembly.CodeBase might help to locate the images; Assembly.Location indicates the temporary directory.

Assembly.CodeBase can be used in code that is shared between ASP.NET and .NET. Server.MapPath can also be used (as suggested by Marko), but it works in ASP.NET only.

The best place to ask PDFsharp and MigraDoc Foundation related questions is the PDFsharp forum. The PDFsharp Team will not monitor stackoverflow.com on a regular basis.

PDFsharp Forum:
http://forum.pdfsharp.net/

PDFsharp Website:
http://www.pdfsharp.net/

PDFsharp Team
Why was this voted down?
Marko
@PDFSharp Team - i still can't get this working . . do you know if anyone has successfully done this ?
ooo
We only used it without MVC so far.But here's a "confession":http://forum.pdfsharp.net/viewtopic.php?p=3833#p3833
PDFsharp Team
A: 

The MigraDoc Document object has an ImagePath property that allows you to specify the directories that will be searched for images (separate multiple directories with semikola).

If images can be found relative to the location of the assembly, then Assembly.CodeBase can be used to locate the assembly (as mentioned in my earlier answer).

The best place to ask PDFsharp and MigraDoc Foundation related questions is the PDFsharp forum. The PDFsharp Team will not monitor stackoverflow.com on a regular basis.

PDFsharp Forum:
http://forum.pdfsharp.net/

PDFsharp Website:
http://www.pdfsharp.net/

PDFsharp Team