example20_justify.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. $html = '
  3. <h1>mPDF</h1>
  4. <h2>Justification</h2>
  5. <h4>Tables</h4>
  6. <p>Text can be justified in table cells using in-line or stylesheet CSS. (Note that &lt;p&gt; tags are removed within cells along with any style definition or attributes.)</p>
  7. <table class="bpmTopnTailC"><thead>
  8. <tr class="headerrow"><th>Col/Row Header</th>
  9. <td>
  10. <p>Second column header p</p>
  11. </td>
  12. <td>Third column header</td>
  13. </tr>
  14. </thead><tbody>
  15. <tr class="oddrow"><th>Row header 1</th>
  16. <td>This is data</td>
  17. <td>This is data</td>
  18. </tr>
  19. <tr class="evenrow"><th>Row header 2</th>
  20. <td>
  21. <p>This is data p</p>
  22. </td>
  23. <td>
  24. <p>This is data</p>
  25. </td>
  26. </tr>
  27. <tr class="oddrow"><th>
  28. <p>Row header 3</p>
  29. </th>
  30. <td>
  31. <p>This is long data</p>
  32. </td>
  33. <td>This is data</td>
  34. </tr>
  35. <tr class="evenrow"><th>
  36. <p>Row header 4</p>
  37. <p>&lt;th&gt; cell acting as header</p>
  38. </th>
  39. <td style="text-align:justify;"><p>Proin aliquet lorem id felis. Curabitur vel libero at mauris nonummy tincidunt. Donec imperdiet. Vestibulum sem sem, lacinia vel, molestie et, laoreet eget, urna. Curabitur viverra faucibus pede. Morbi lobortis. Donec dapibus. Donec tempus. Ut arcu enim, rhoncus ac, venenatis eu, porttitor mollis, dui. Sed vitae risus. In elementum sem placerat dui. Nam tristique eros in nisl. Nulla cursus sapien non quam porta porttitor. Quisque dictum ipsum ornare tortor. Fusce ornare tempus enim. </p></td>
  40. <td>
  41. <p>This is data</p>
  42. </td>
  43. </tr>
  44. <tr class="oddrow"><th>Row header 5</th>
  45. <td>Also data</td>
  46. <td>Also data</td>
  47. </tr>
  48. <tr class="evenrow"><th>Row header 6</th>
  49. <td>Also data</td>
  50. <td>Also data</td>
  51. </tr>
  52. <tr class="oddrow"><th>Row header 7</th>
  53. <td>Also data</td>
  54. <td>Also data</td>
  55. </tr>
  56. <tr class="evenrow"><th>Row header 8</th>
  57. <td>Also data</td>
  58. <td>Also data</td>
  59. </tr>
  60. </tbody></table>
  61. <p>&nbsp;</p>
  62. <h4>Testing Justification with Long Words</h4>
  63. <p>http://www-950.ibm.com/software/globalization/icu/demo/converters?s=ALL&amp;snd=4356&amp;dnd=4356</p>
  64. <h5>Should not split</h5>
  65. <p>Maecenas feugiat pede vel risus. Nulla et lectus eleifend <i>verylongwordthatwontsplit</i> neque sit amet erat</p>
  66. <p>Maecenas feugiat pede vel risus. Nulla et lectus eleifend et <i>verylongwordthatwontsplit</i> neque sit amet erat</p>
  67. <h5>Non-breaking Space &amp;nbsp;</h5><p>The next example has a non-breaking space between <i>eleifend</i> and the very long word.</p><p>Maecenas feugiat pede vel risus. Nulla et lectus eleifend&nbsp;verylongwordthatwontsplitanywhere neque sit amet erat</p><p>Nbsp will only work in fonts that have a glyph to represent the character i.e. not in the CJK languages nor some Unicode fonts.</p>
  68. <h4>Testing Justification with mixed Styles</h4>
  69. <p>This is <s>strikethrough</s> in <b><s>block</s></b> and <small>small <s>strikethrough</s> in <i>small span</i></small> and <big>big <s>strikethrough</s> in big span</big> and then <u>underline</u> but out of span again but <font color="#000088">blue</font> font and <acronym>ACRONYM</acronym> text</p>
  70. <p>This is a <font color="#008800">green reference<sup>32-47</sup></font> and <u>underlined reference<sup>32-47</sup></u> then reference<sub>32-47</sub> and <u>underlined reference<sub>32-47</sub></u> then <s>Strikethrough reference<sup>32-47</sup></s> and <s>strikethrough reference<sub>32-47</sub></s> and then more text.
  71. </p>
  72. <p><big>Repeated in <u>BIG</u>: This is reference<sup>32-47</sup> and <u>underlined reference<sup>32-47</sup></u> then reference<sub>32-47</sub> and <u>underlined reference<sub>32-47</sub></u> but out of span again but <font color="#000088">blue</font> font and <acronym>ACRONYM</acronym> text</big>
  73. </p>
  74. <p><small>Repeated in small: This is reference<sup>32-47</sup> and <u>underlined reference<sup>32-47</sup></u> then reference<sub>32-47</sub> and <u>underlined reference<sub>32-47</sub></u> but out of span again but <font color="#000088">blue</font> font and <acronym>ACRONYM</acronym> text</small>
  75. </p>
  76. <p style="font-size:7pt;">This is <s>strikethrough</s> in block and <big>big <s>strikethrough</s> in big span</big> and then <u>underline</u> but out of span again but <font color="#000088">blue</font> font and <acronym>ACRONYM</acronym> text</p>
  77. <p style="font-size:7pt;">This is reference<sup>32-47</sup> and <u>underlined reference<sup>32-47</sup></u> then reference<sub>32-47</sub> and <u>underlined reference<sub>32-47</sub></u> then <s>Strikethrough reference<sup>32-47</sup></s> and <s>strikethrough reference<sub>32-47</sub></s> then more text.
  78. </p>
  79. <p></p>
  80. <p style="font-size:7pt;">
  81. <big>Repeated in BIG: This is reference<sup>32-47</sup> and <u>underlined reference<sup>32-47</sup></u> then reference<sub>32-47</sub> and <u>underlined reference<sub>32-47</sub></u> but out of span again but <font color="#000088">blue</font> font and <acronym>ACRONYM</acronym> text</big>
  82. </p>
  83. ';
  84. //==============================================================
  85. //==============================================================
  86. //==============================================================
  87. include("../mpdf.php");
  88. $mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
  89. $mpdf->SetDisplayMode('fullpage');
  90. // LOAD a stylesheet
  91. $stylesheet = file_get_contents('mpdfstyletables.css');
  92. $mpdf->WriteHTML($stylesheet,1); // The parameter 1 tells that this is css/style only and no body/html/text
  93. $mpdf->WriteHTML($html);
  94. // SPACING
  95. $mpdf->WriteHTML("<h4>Spacing</h4><p>mPDF uses both letter- and word-spacing for text justification. The default is a mixture of both, set by the configurable values jSWord and jSmaxChar. (Only word spacing is used when cursive languages such as Arabic or Indic are detected.) </p>");
  96. $mpdf->jSWord = 0; // Proportion (/1) of space (when justifying margins) to allocate to Word vs. Character
  97. $mpdf->jSmaxChar = 0; // Maximum spacing to allocate to character spacing. (0 = no maximum)
  98. $mpdf->WriteHTML("<h5>Character spacing</h5><p>Maecenas feugiat pede vel risus. Nulla et lectus eleifend <i>verylongwordthatwontsplitanywhere</i> neque sit amet erat</p>");
  99. // Back to default settings
  100. $mpdf->jSWord = 0.4;
  101. $mpdf->jSmaxChar = 2;
  102. $mpdf->WriteHTML("<h5>Word spacing</h5><p style=\"letter-spacing:0\">Maecenas feugiat pede vel risus. Nulla et lectus eleifend <i>verylongwordthatwontsplitanywhere</i> neque sit amet erat</p>");
  103. $mpdf->WriteHTML("<h5>Mixed Character and Word spacing</h5><p>Maecenas feugiat pede vel risus. Nulla et lectus eleifend <i>verylongwordthatwontsplitanywhere</i> neque sit amet erat</p>");
  104. // ORPHANS
  105. $mpdf->WriteHTML("<h4>Orphans</h4><p>Punctuation marks should not be split when the last word on a line is in &lt;tags&gt; eg <acronym>NATO</acronym>. The punctuation should go to the next line with the word if necessary.</p>");
  106. $mpdf->WriteHTML("<p>Punctuation marks should not be split when the last word on a line is in &lt;tags&gt; e.g. <acronym>UNESCO</acronym>. The punctuation should go to the next line with the word if necessary.</p>");
  107. $mpdf->WriteHTML("<p>Single marks .,?!;:\xe2\x80\x9e\xe2\x80\x9d should be preserved when last word on a line is in &lt;tags&gt; e.g. <acronym>NATO</acronym>? All of these are automatically protected in mPDF.</p>");
  108. $mpdf->orphansAllowed = 0;
  109. $mpdf->WriteHTML("<p>Similarly, sub and super texts should not be split when justifying text such as references<sup>23</sup>. (Note that this sentence has the orphansAllowed set to zero.) Altering the value of \$mpdf->orphansAllowed will determine how many extra characters can be preserved on a line; the next line allows 3 (default value 5):</p>");
  110. $mpdf->orphansAllowed = 3;
  111. $mpdf->WriteHTML("<p>Similarly, sub and super texts should not be split when justifying text such as references<sup>23</sup>. The references should go to the next line with the word if necessary, or remain on the same line.</p>");
  112. $mpdf->Output();
  113. exit;
  114. ?>