question

leventkoman-0613 avatar image
0 Votes"
leventkoman-0613 asked Bruce-SqlWork answered

How can I run javascript codes, css files and javascript files into wkhtmltopdf in asp.net core api project?

I use the Chart.js library to draw charts, but I use the wkhtmltopdf library to convert pdf. But my javascrip codes and css codes are not working. How can I make it work?

dotnet-aspnet-generaldotnet-aspnet-core-webapidotnet-aspnet-core-razor
· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @leventkoman-0613,

Do you mean you create a web page and use Chart.js to draw charts, before using the wkhtmltopdf library to convert pdf, everything works well (the JS and CSS code), but after using the wkhtmltopdf library to convert the html page to pdf, the JS and CSS code will not work, right? If that is the case, this issue relates to the wkhtmltopdf library, you can contact the wkhtmltopdf team, whether it supports the JS and CSS file when convert to pdf.

1 Vote 1 ·

Thank you for your comment. I added kods my project but not working chart.js. I couldn't find the answer to this question anywhere. This is my detail question. https://stackoverflow.com/questions/72668882/how-can-i-run-javascript-codes-css-files-and-javascript-files-into-wkhtmltopdf.

0 Votes 0 ·
AgaveJoe avatar image AgaveJoe leventkoman-0613 ·

You misunderstand Web API, MVC, and the wkhtmltopdf library. Web API returns data, usually JSON, not an HTML View. MVC returns an HTML View. Seems logical to me that a library with "HTML to PDF" in the name does not work with Web API.


0 Votes 0 ·
Show more comments

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

the links to css and js files must be either full url with server (and no security) or absolute file paths (relative path are not supported with string input html

what do your links look like?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.