Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 884
leora Avatar asked Jul 06 '10 02:07

leora


2 Answers

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.

like image 185
I liked the old Stack Overflow Avatar answered Sep 22 '22 02:09

I liked the old Stack Overflow


It might be looking for a full path?

Try

Image image13 = section.AddImage(Server.MapPath("~/images/logo.png"));
like image 24
Marko Avatar answered Sep 23 '22 02:09

Marko