How to add image in pdf file - asp.net-mvc

I have used this blog for adding a dynamic pdf in my project. when i am tryng to add a image than it is compelling me to have a Image folder in C:\ . How can i add a image from project.

This appears to be using a html view page to render the PDF so you can just use a normal img tag like you would in any html page.
With razor syntax you can do something like this:
<img alt="" src="#Url.Content("~/Content/Images/mypic.png")" />
I believe this may solve your issue. Essentially you want to specify the full web url as the src of the img, for example:
<img alt="" src="www.example.com/images/mypic.png" />

Related

Serving image in Thymeleaf template

I have an email template where I want to serve a static png file, I have tried every possible method, but it is still broken in the email.
src/resources/templates/emailTemplates is the directory for my thymeleaf template file and src/resources/assets is the directory of my logo.png file
This is my html code:
<a target="_blank"
th:href="${WebAppUrl}">
<img
th:src="#{../../assets/logo.png}"
/>
</a>
I have tried adding the src too, tried cid etc. It's still not working.

Serving WebP Images to Visitors Using HTML Elements

Digital Ocean suggests the following format for webp images:
<picture>
<source srcset="logo.webp" type="image/webp">
<img src="logo.png" alt="Site Logo">
</picture>
In the example below I have applied a class to the jpg. Is it a good idea (or necessary) to apply the same class to the webp? How about adding the alt tag? Do webp images need an alt tag?
<picture>
<source srcset="images/pic.webp" type="image/webp">
<img src="images/pic.jpg" class="img-fluid" alt="">
</picture>
I assume you are referring to this article.
While it's certainly possible to use the picture and source elements, there are reasons against it:
not supported by all browsers (although it will fall back to the inside img)
complexifies html code
requires rewriting of existing code
The alternative option is to use Apache’s mod_rewrite module to automate the process of serving .webp images to supporting browsers (also in the article). The advantages being:
supported by all browsers
simpler html
no need to rewrite existing code

Using AutoFileName with Sublime Text 2

I have installed the package 'AutoFileName' but when I try to define an img source I recieve only tag options and not images. Does anyone know if I have to define the folder where my images are or where AutoFileName looks for images?
AutoFileName lists files based on the html file you edit. For example, if test1.img, test2.img and test.html are in the same folder, it will list test1.img and test2.img if you are trying to add <img src=""> in test.html.

PDFkit doesn't display pictures in PDF

Rails 2, PDFkit 0.5.0
Im generating a PDF from a View in Rails 2 with PDFkit and everything works fine. The only thing which doesn't work is displaying pictures in the pdf.
When I look at the View in the Browser, the picture is there but its missing in the PDF. There is only a placeholder existing in the PDF.
The image_tag is looking like this:
<%= image_tag('plus.gif') %>
I also tried to realize it with a css-file but it doesn't work either.
Any ideas?
Because of the way that wkhtmltopdf works you need to specify the full path to any assets (JS, CSS, images etc), including the domain name.
This won't work:
<img src="/images/foo.png" />
This will:
<img src="http://example.com/images/foo.png" />
One workaround is to set an explicit asset host, even if it's the same server as your app is running on (see the AssetTagHelper documentation for details). Another would be to specify the hostname in the image_tag.
Instead of putting the full path each time, you can add a base tag to the head section.
<base href="http://mydomain.com" target="_blank" />

Where do you store images for asp.net mvc projects and how do you reference them from site.master

I have a new asp.net mvc project and i am trying to figure out the best place to store images and also how i would reference them from site.master (in cases where i have a header images that i want to show up on all pages).
Suggestions or best practices?
What I generally do is create an "Images" folder inside my Content folder. Where you place your images is really up to you, as long as you are consistent.
Referencing these images from your Site.Master is the same as if you referenced it from any view:
<img src="/Content/Images/mylogo.png" />
<img src="#Url.Content("~/Content/Images/logo.png")" />
Using this in a Razor view on MVC 5. Images are stored in /Content/Images.
<%=Html.Image("~/Content/Images/xxx.png")%>
This resolves from wherever you are in the site hierarchy. Html.Image is a part of the the Microsoft.Web.Mvc futures assembly.
or in mvc2:
<img src="<%: Url.Content("~/Images2/landingMain/safety.png") %>" alt="safety" />
U must put all your images in Content Folder like :-
Content-->Images-->.IMG files and
same as style sheet files
Content Folder like Content-->.css hence it easily load the images and css otherwise it is not executed in proper manner.

Resources