0

I tried to convert html to pdf by using DinkToPDF.

Unfortunately the pdf result is different than source HTML.

Here are my DinkToPdf settings:

var globalSettings = new GlobalSettings
{
    ColorMode = ColorMode.Color,
    Orientation = Orientation.Portrait,
    PaperSize = PaperKind.A4,
    DocumentTitle = title,
    Out = string.Empty,
};

var objectSettings = new ObjectSettings
{
    PagesCount = true,
    HtmlContent = htmlBody,
    WebSettings = { DefaultEncoding = "utf-8" }
};

Sample Source HTML

sample source html

Sample PDF result

dinktopdf result

Is it a bug? Or is there something wrong with my code?

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • A PDF is not a browser. It will render differently. You just have to make a simplified html page for pdf or create a PDF without html. – VDWWD Aug 05 '20 at 09:03

2 Answers2

1

DinkToPdf is based on wkhtmltopdf and doesn't support a lot of modern CSS.

See this StackOverflow post on DinkToPdf.

benhorgen
  • 1,928
  • 1
  • 33
  • 38
zvons
  • 11
  • 3
0

Its not a Bug. As explained by @zvons, it wont support Modern CSS like Flexbox. Further there are many Global settings which alter font depth, spacing etc. between characters.

Eg: DPI is important setting for PDF. This cant be done from CSS. Alter Global settings to achieve the result.