0

I'm stuck with trying to get hyphenation to work in dompdf. My idea was to use hyphenator.js on the html that I feed to dompdf.

So far I've tried the following:

  1. Include the hyphenator.js file in a <script src in the header
  2. Include the hyphenator.js file in a <script src in the body
  3. Include the hyphenator source code directly in the body

When I render the page in my browser, hyphenator.js works perfectly in all of the three cases. Yet it doesn't work in dompdf at all. Am I missing something?

This is really crucial, because I will also need to use JavaScript for dynamic absolute placement of content.

And if JavaScript doesn't work at all, are there any other hyphenation options?

Thank you very much in advance!

halfer
  • 19,824
  • 17
  • 99
  • 186
nils
  • 25,734
  • 5
  • 70
  • 79

1 Answers1

3

dompdf does not run JavaScript. If you need that type of functionality you have two options:

  1. Load the document in your web browser and use JS to capture the content after hyphenation has been applied and send it to the server for rendering by domopdf. This, of course, only works if your document's web layout appropriately mimics the print layout (e.g. text line width).
  2. Use a browser-based PDF renderer such as wkhtmltopdf

Ideally you wouldn't need to use a JS library for this. The CSS3 spec supports hyphenation. However, this isn't something that's been addressed in dompdf yet.

BrianS
  • 13,284
  • 15
  • 62
  • 125
  • has it been adressed 10 years later? – nerdess Jul 06 '23 at 08:01
  • Dompdf will likely never support JavaScript-based functionality. Built-in hyphenation support is still not available and unlikely to be implemented anytime soon. – BrianS Aug 04 '23 at 21:42