I am working on displaying an image on a webpage that is exported to a pdf using the IronPDF library. The problem I am having is that changing the img tag in cshtml is causing the image to either display in the PDF or the webpage but not both.
Image file is stored in wwwroot/images
folder.
Current img tag:
<img src="../images/Logo.png" alt="Logo" align="right" style="width:150px">
This displays the image in the PDF but not on the webpage. If I change the src to be .../images/Logo.png
, that displays on the webpage but not the pdf.
PDF create method:
public string CreateAddendumPDF(string html, string agreementID)
{
var render = new ChromePdfRenderer();
render.RenderingOptions.MarginLeft = 17;
render.RenderingOptions.MarginRight = 15;
render.RenderingOptions.MarginTop = 14;
render.RenderingOptions.FirstPageNumber = 1;
var pdf = render.RenderHtmlAsPdf(html,@"wwwroot/images");
string rootPath = _webHostEnvironment.WebRootPath;
string path = Path.Combine(rootPath, ReportConstants.Temp + "Addendums\\" + agreementID + "_" +"Addendum.pdf");
pdf.SaveAs(path);
return path;
}
I tried different image src values and could not get one to work in both the webpage and the pdf document. Next solution is to use Jquery to change the image tag when the user clicks the download pdf button.