images shown in .html but not in pdf

49 Views Asked by At

I have a .html file under Content/Templates which has some images as background:

.page1 {
        background-image: url('../../images/productdocuments/image1.jpg'); 
        background-size cover;
    }

and images inside:

<div class="image-container">
            <img class="image" id="mainImage" src="@url" style="width: 124%; height: 81%; margin-left: 4cm;">
        </div>

All images are visible in the .html preview. I am generating a pdf using the template and NReco.PdfGenerator

...

 var PdfFile = Tools.ConvertfromHtmltoPdf(Tools.CreatePdf(cPdf));

...

 public static byte[] ConvertfromHtmltoPdf(string HtmlContent)
            {
    
                if (String.IsNullOrWhiteSpace(HtmlContent))
                    return null;
                var converter = new NReco.PdfGenerator.HtmlToPdfConverter();
                return converter.GeneratePdf(HtmlContent);
            }

And CreatePdf is:

public static string CreatePdf(CPdf cPdf)
        {
            if (cPdf != null)
            {
                string path = HttpContext.Current.Server.MapPath(@"\Content\Templates\PTemplate.html");
                if (File.Exists(path))
                {
                    string htmltemplate = File.ReadAllText(path), detail = "";     
                    htmltemplate = htmltemplate.Replace("@categoryurl", cPdf.Picture);
                    return htmltemplate;
                }
            }
            return "";
        }

I see cPdf.Picture is a URL but why any of these images are not shown on the pdf file?

0

There are 0 best solutions below