html2pdf.js: CSS rules are not getting applied
Thanks for the library. I was using jspdf that was showing black screen. This lib works fine but, the css rules are not getting applied. This is how I am using this with Angular
Installed
yarn add html2pdf.js
and then in my .ts file
import * as html2pdf from "html2pdf.js";
and
var opt = {
margin: 1,
filename: 'Invoice.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf(__domElement, opt);
And this is the DOM element
and this is the output
any solutions?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 21 (2 by maintainers)
I had the same issue.
Im using Vue as a fronted framework and I didn’t want to use in-line styles, so I solved by doing the following :
I had this before and it didn’t working:
I remembered that for all classes in Vue to work as expected, they have to be inside the class .v-application, so I did this change:
Once I made that change, the Vue classes started showing in the PDF.
@eKoopmans Thanks for the reply, Actually the CSS rules that are written in .css files are not getting applied, so i copied directly to my html (inline styling <style>), And now this is working perfectly fine.
Yes sure, I will try the given link as well.
Thanks!!! 😃
I guess it is, i also have no css here when generating pdf from vue
It was an easier fix for me. I wasn’t seeing any styling, until I realised the CSS was loading after the script.
I put the css above the script and now the PDF is beautiful.
Thanks!
@Zankhna95, you’d need to compile this to css first at the very least I would say.