简体   繁体   中英

Refer local disk image in C# html string

I am generating a pdf document using DinkToPdf and need to embed an image (present in the release folder) using img tag.

I followed this SO Post: Adding <img> HTML tag to C# String

But it only works for internet URLs and not for local disk images

What I tried is var HTML = @"<img src=""/myimage.png""/>"

But no image is displayed once the PDF is generated. But works fine if the path is an internet URL

How can I solve this?

[Edit to clarify the question] The image resides in the server and this needs to be embedded in the first page of the document

You need to specify full path like this if you have your image in folder \wwwroot\Documents\ImgName.jpg

<img src="https://localhost:50001/Documents/ImgName.jpg">
        

Full path is not needed. Make sure your relative path is correct.

<img src=""/myimage.png""/>" Does the image resides on same executing environment?

If not use ~ to go back a directory. Image cannot exist on different project. It should be same as executing project.

A screenshot of folder structure would be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM