0

I create a method to convert the HTML to HTMLString and convert it to pdf and I put the baseUrl; however, there are no pictures in pdf.

It is the screenshot of the pdf output

 public FileResult PrintTest3(int id)
        {
            var viewModel = new StandardIndexData();
            viewModel.Title = _context.Titles.Where(i => i.Id == id).FirstOrDefault();
            viewModel.Sections =  _context.Sections;

            viewModel.FileManagers =  _context.FileManagers.ToArray();
            viewModel.Items = _context.Items.Include(i=>i.FileManagers);
            
            var html = Helper.RenderRazorViewToString(this, "DisplayAll",viewModel);
            HtmlToPdf oHtmlToPdf = new HtmlToPdf();
            //var baseUrl = "~//Images";
            PdfDocument oPdfDocument = oHtmlToPdf.ConvertHtmlString(html, _dir);
            byte[] pdf = oPdfDocument.Save();
            oPdfDocument.Close();
            return File(pdf, "application/pdf", "Test.pdf");
        }

Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
Sean166
  • 3
  • 3

1 Answers1

0

This is because base baseUrl is not correct, the right way is:

baseUrl + relative image/css url = full absolute url

base Url=>http://domain or local host relative image/css url=>your image file address

Ex=>http://localhost:54883/images/SmartPaies/clients-logo/

still not work please let me know you can also reach me on my mail id mimamsalabs@gmail.com