Search code examples
htmlmodel-view-controllerhtml-to-pdfhiqpdf

Background image are not loaded in HiQPDF


I am using HiQPDF to convert HTML to PDF. Everything working fine but background images are not displayed in converted PDF file. Please check below code and suggest me what I am doing wrong. Please note I am using MVC with .Net 4.7 and using HiQPDF version 10.

public ActionResult PdfDownload(string slug)
    {
        var dto = _theMonthlyFrontService.GetMonthlyDetail(slug);


        var html = this.RenderView("view", dto).Replace("\r\n", "").Replace("\n", "").Replace("{%WebsiteUrl%}", "");

        var htmlToPdfConverter = new HtmlToPdf { SerialNumber = "HiqPdfKey" };
        htmlToPdfConverter.Document.PageSize = PdfPageSize.A4;
        htmlToPdfConverter.Document.Margins.Top = 50;
        htmlToPdfConverter.Document.Margins.Bottom = 50;

        var pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(html, "http://localhost/");

        FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf")
        {
            FileDownloadName = "download.pdf"
        };

        return fileResult;
    }

Solution

  • I have checked the css and found that background images were not visiable due to some opacity and z-index CSS. So I have applied the following css and now the images are displayed fine

    .large-gallery {
        opacity: 1 !important;
        z-index : auto !important;
    }