I have HTML code with many elements with style position: absolute. The HTML code looks good in the browser but when I try to convert it to pdf using HtmlRenderer.PdfSharp, I get all the elements in the top left corner. How can I fix this?
Here is my code:
using PdfSharp;
using PdfSharp.Pdf;
using TheArtOfDev.HtmlRenderer.PdfSharp;
var html = "...";
File.WriteAllBytes("draft.html", Encoding.UTF8.GetBytes(html));
using PdfDocument pdf = PdfGenerator.GeneratePdf(html, PageSize.A4, margin:0);
using var ms = new MemoryStream();
pdf.Save(ms);
File.WriteAllBytes("draft.pdf", ms.ToArray());
return ms.ToArray();
I have HTML code with many elements with style position: absolute. The HTML code looks good in the browser but when I try to convert it to pdf using HtmlRenderer.PdfSharp, I get all the elements in the top left corner. How can I fix this?
Here is my code:
The html:
Below is how the generated pdf looks like: