0

I'm following the example specified in this location to convert an existing HTML to Accessible PDF.

https://developers.itextpdf.com/de/content/itext-7-examples/itext-7-converting-html-pdf/pdfhtml-accessible-pdf-creation

Is there a way to pass CSS as string to the PDF converter instead of specifying it in the html file itself? I need to switch the CSS based on user preference. Specifying it inline in the HTML is not an option. The CSS that will be applied is read from a CMS system on the fly.

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
RKodakandla
  • 3,318
  • 13
  • 59
  • 79

1 Answers1

0

Behind the scenes, iText uses JSoup to parse the input HTML document. This means you already have a (hidden) dependency on JSoup.

The easiest way of implementing your functionality (in my opinion) would be to parse the document with JSoup and add an extra 'style' element in the header, with the CSS content you want.

You can then render the entire document to a string, and feed the string to pdfHTML.

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54