Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

835
Views
Pass css file into PDFMake styles

I'm currently trying to print a string containing HTML markup to pdf using the HTML-to-pdfmake and pdf make libraries. The HTML contains a lot of classes and ids and I have styling for those in a CSS file. Is there a way to pass that CSS file to the styles attribute in pdfmake instead of writing all the styles in the content definition section?

This is what I currently have:

   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",
      },
    },
  }

The goal would be to reference these styles from a css instead as I have a 1000 lines long css styling. So would be something like this:

   let documentDefinition = {
    pageSize: "A4",
    pageOrientation: "portrait",
    footer: footer,
    header: header,
    content: [
      {
        text: htmlToPdfmake(documentBody, {
          window: window,
        }),
      },
    ],
    styles: {
      path: "./styles/style.css"

    }
     
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

FYI: pdfmake style's are not CSS and the html-to-pdfmake module only supports a limited set of CSS properties.

CSS can create very complex design, however this framework can only handle the most simple HTML / CSS. The support of CSS style is limited and might not work in all cases with all values:

Having said that, if you want to externalize this part of your configuration you can move it to a different JS (or even JSON) file and load it using your favorite module loader, as you would with any regular JS or JSON file.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!