My current task involves converting a string with HTML markup into a PDF using the HTML-to-pdfmake and pdf make libraries. The HTML code includes numerous classes and ids, with corresponding styles defined in a CSS file. Rather than manually adding all the styles to the content definition section, I am wondering if there is a way to pass the CSS file to the styles
attribute in pdfmake.
This is my current setup:
let documentDefinition = {
pageSize: "A4",
pageOrientation: "portrait",
footer: footer,
header: header,
content: [
{
text: htmlToPdfmake(documentBody, {
window: window,
}),
},
],
styles: {
header: {
fontSize: 22,
bold: true,
},
anotherStyle: {
italics: true,
alignment: "right",
},
},
}
I aim to streamline this process by linking these styles directly from a CSS file, which contains a significant amount of styling rules. The desired implementation would look something like this:
let documentDefinition = {
pageSize: "A4",
pageOrientation: "portrait",
footer: footer,
header: header,
content: [
{
text: htmlToPdfmake(documentBody, {
window: window,
}),
},
],
styles: {
path: "./styles/style.css"
}
}