I have a pdf invoice created using .Net Core 3 Web API
and DinkToPdf
library.
Now I need to insert into pdf an image as signature. I created the Resource folder of my project and add the image with the Copy to Output Directory
set to allways
. But I don't know how to use it in my string value which contain all the pdf data.
var htmlDoc = new StringBuilder();
...
htmlDoc.AppendLine("<td>");
// here I need to insert the image
Stream imgStream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("Project.Resources.signature.jpeg"); // is allways null
or
htmlDoc.AppendLine("<img src=\"Project.Resources.signature.jpeg\" />");
htmlDoc.AppendLine("</td>");
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
ColorMode = ColorMode.Color,
Orientation = Orientation.Landscape,
PaperSize = PaperKind.A4Plus,
Margins = new MarginSettings() { Top = 10, Left = 30, Right = 30 }
},
Objects = {
new ObjectSettings() {
PagesCount = true,
HtmlContent = htmlDoc.ToString(),
WebSettings = { DefaultEncoding = "utf-8" }
}
}
};
var pdf = converter.Convert(doc);
var stream = new MemoryStream(pdf);
var contentType = @"application/pdf";
var fileName = $"Invoice_{entity.Id}.pdf";
stream.Seek(0, SeekOrigin.Begin);
return File(stream, contentType, fileName);
Startup.cs:
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
edit: I found absolute path works
htmlDoc.AppendLine("<img src=\"C/User/Application/Project/Resources/signature.jpeg\" />");
But, this is not an optimal solution because the absolute path of local environment is different of production environment .
any other idea? thanks