DOMPDF word-wrap

3.4k views Asked by At

I have following html code:

<p><strong>Lorem Ipsum</strong> je fiktívny text, používaný pri návrhu tlačovín a typografie. Lorem Ipsum je štandardným výplňovým textom už od 16. storočia, keď neznámy tlačiar zobral sadzobnicu plnú tlačových znakov a pomiešal ich, aby tak vytvoril vzorkovú knihu. <em>Prežil nielen päť storočí</em>, ale aj skok do elektronickej sadzby, a pritom zostal v podstate nezmenený.</p>

After convert to pdf look this: enter image description here

I try use word-wrap and also this: dompdf does wrong calculation for line breaks breaking words but not working for me.

In slovak language can not be "a" in the end of line. I need to have it like this:

"..tlačovín a typo-
grafie..."

or

 "...tlačovín
   a typografie..."

same problem in last but one with "v"

also we cant use numbers and century separately

"16.
storočia"

i need to have it like this:

už od
16. storočia, ... (together)

This problem can solve in html when i type 16.storočia without spacer.

2

There are 2 answers

0
BrianS On

dompdf does not have language parsing rules for languages other than English at this time (though investigating how to implement those rules might be worthwhile in the future). dompdf also does not yet support hyphenation. Initial support would be implemented for English first and non-English languages later.

Your particular problem, however, is addressable with some tweaks to the HTML. You can prevent a line break by surrounding a set of characters with the nobr element. I tweaked your sample text in the following CSS/HTML:

@page {
  size: letter portrait;
}

body {
  font-family: DejaVu Sans, sans-serif; font-size: 125%;  
}
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
  <p><b>Incorrect wrapping</b></p>
  <p><strong>Lorem Ipsum</strong> je fiktívny text, používaný pri návrhu tlačovín a typografie. Lorem Ipsum je štandardným výplňovým textom už od 16. storočia, keď neznámy tlačiar zobral sadzobnicu plnú tlačových znakov a pomiešal ich, aby tak vytvoril vzorkovú knihu. <em>Prežil nielen päť storočí</em>, ale aj skok do elektronickej sadzby, a pritom zostal v podstate nezmenený.</p>
  <p><b>Correct wrapping</b></p>
  <p><strong>Lorem Ipsum</strong> je fiktívny text, používaný pri návrhu tlačovín <nobr>a typografie</nobr>. Lorem Ipsum je štandardným výplňovým textom už od <nobr>16. storočia</nobr>, keď neznámy tlačiar zobral sadzobnicu plnú tlačových znakov a pomiešal ich, aby tak vytvoril vzorkovú knihu. <em>Prežil nielen päť storočí</em>, ale aj skok do elektronickej sadzby, <nobr>a pritom</nobr> zostal <nobr>v podstate</nobr> nezmenený.</p>
</body>
</html>

(I did my best to mark up the text to wrap correctly based on your question, but I don't have knowledge of all the language rules.)

0
moeses On

Puuhh dompdf again - we use it on a drupal-project and this plugin made me angry several times. CSS2 and not CSS3-Support, no JS and buggy as hell!!

What you can do is putting the 16. storocia in a 16. storocia - This should keep them together. To the two other issues you have, try to wrap them in a span too.

It's not the best workaround but i think with typographic problems like these you'll always have to do all this "fine-tuning" by hand.

I hope i could help a little