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 include CSS like Bootstrap in my HTML so that I can observe the applied styles when generating a PDF? #120

Closed AlexCorsega closed 9 months ago

AlexCorsega commented 9 months ago

My HTML has CSS files I tried to link an external and internal CSS but its not working. When I generate the PDF, the styles is not applied to the PDF file.

HakanL commented 9 months ago

There's a setting called BlockLocalFileAccess which is probably the cause of this.

AlexCorsega commented 9 months ago

I tried to set the BlockLocalFileAccess to false and still the applied styles is not showing in the PDF.

Here's my code: image

Do you think there's a problem with it?

HakanL commented 9 months ago

Looks correct. What does your stylesheet reference look like? Maybe test it using the native wkhtmltopdf tool first to see if it works there.

AlexCorsega commented 9 months ago

Here's my stylesheet look like.

 <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
 <link rel="stylesheet" href="C:/Users/User/Downloads/bootstrap-5.3.2-dist/bootstrap-5.3.2-dist/css/bootstrap.css" />

On top of that was an internal style of bootstrap in hope that It will work. I tested everything but the applied styles is not reflected to the PDF.

HakanL commented 9 months ago

I read somewhere that you need to use file:// for the links, try that. If that doesn't work then try the native library and report the issue there, since this project here is just a wrapper.

AlexCorsega commented 9 months ago

Okay thank you for your help.