HakanL / WkHtmlToPdf-DotNet

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
GNU Lesser General Public License v3.0
366 stars 66 forks source link

How can I set html code with css in header #99

Closed Su1N closed 1 year ago

Su1N commented 1 year ago

I want to make my pdf's header also have css.

HakanL commented 1 year ago

I don't think that's supported, but it's best to raise this question with wkhtmltopdf as this project is simply a wrapper for .NET around the native library that does all the heavylifting.

FransdeJong commented 1 year ago

@Su1N I managed to style the header and footer using a global css file that I added in the Objectsettings in the UserStyleSheet:

new ObjectSettings { PagesCount = true, HtmlContent = htmlString, WebSettings = { DefaultEncoding = "utf-8", LoadImages= true, PrintMediaType = false, UserStyleSheet = pdfViewModel.StyleSheet }, HeaderSettings = { Spacing = 20, HtmlUrl = pdfViewModel.HeaderUrl }, FooterSettings = { Spacing= 30, HtmlUrl = pdfViewModel.FooterUrl } }