example_046.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. //============================================================+
  3. // File name : example_046.php
  4. // Begin : 2009-02-28
  5. // Last Update : 2010-08-08
  6. //
  7. // Description : Example 046 for TCPDF class
  8. // Text Hyphenation
  9. //
  10. // Author: Nicola Asuni
  11. //
  12. // (c) Copyright:
  13. // Nicola Asuni
  14. // Tecnick.com s.r.l.
  15. // Via Della Pace, 11
  16. // 09044 Quartucciu (CA)
  17. // ITALY
  18. // www.tecnick.com
  19. // info@tecnick.com
  20. //============================================================+
  21. /**
  22. * Creates an example PDF TEST document using TCPDF
  23. * @package com.tecnick.tcpdf
  24. * @abstract TCPDF - Example: text Hyphenation
  25. * @author Nicola Asuni
  26. * @since 2009-02-28
  27. */
  28. require_once('../config/lang/eng.php');
  29. require_once('../tcpdf.php');
  30. // create new PDF document
  31. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  32. // set document information
  33. $pdf->SetCreator(PDF_CREATOR);
  34. $pdf->SetAuthor('Nicola Asuni');
  35. $pdf->SetTitle('TCPDF Example 046');
  36. $pdf->SetSubject('TCPDF Tutorial');
  37. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  38. // set default header data
  39. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 046', PDF_HEADER_STRING);
  40. // set header and footer fonts
  41. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  42. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  43. // set default monospaced font
  44. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  45. //set margins
  46. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  47. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  48. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  49. //set auto page breaks
  50. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  51. //set image scale factor
  52. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  53. //set some language-dependent strings
  54. $pdf->setLanguageArray($l);
  55. // ---------------------------------------------------------
  56. // set font
  57. $pdf->SetFont('helvetica', 'B', 20);
  58. // add a page
  59. $pdf->AddPage();
  60. $pdf->Write(0, 'Example of Text Hyphenation', '', 0, 'L', true, 0, false, false, 0);
  61. $pdf->Ln(10);
  62. /*
  63. Unicode Data for SHY:
  64. Name : SOFT HYPHEN, commonly abbreviated as SHY
  65. HTML Entity (decimal): &#173;
  66. HTML Entity (hex): &#xad;
  67. HTML Entity (named): &shy;
  68. How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]
  69. UTF-8 (hex): 0xC2 0xAD (c2ad)
  70. */
  71. /*
  72. // You can autmatically add SOFT HYPHENS to your text using
  73. // the hyphenateText() method, but this requires either an
  74. // hyphenation pattern array of a hyphenation pattern TEX file.
  75. // You can download hyphenation TEX patterns from:
  76. // http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
  77. // EXAMPLE:
  78. $html = 'On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.';
  79. $hyphen_patterns = $pdf->getHyphenPatternsFromTEX('../hyphens/hyph-en-gb.tex');
  80. $html = $pdf->hyphenateText($html, $hyphen_patterns, $dictionary=array(), $leftmin=1, $rightmin=2, $charmin=1, $charmax=8);
  81. */
  82. // HTML text with soft hyphens (&shy;)
  83. $html = 'On the other hand, we de&shy;nounce with righ&shy;teous in&shy;dig&shy;na&shy;tion and dis&shy;like men who are so be&shy;guiled and de&shy;mo&shy;r&shy;al&shy;ized by the charms of plea&shy;sure of the mo&shy;ment, so blind&shy;ed by de&shy;sire, that they can&shy;not fore&shy;see the pain and trou&shy;ble that are bound to en&shy;sue; and equal blame be&shy;longs to those who fail in their du&shy;ty through weak&shy;ness of will, which is the same as say&shy;ing through shrink&shy;ing from toil and pain. Th&shy;ese cas&shy;es are per&shy;fect&shy;ly sim&shy;ple and easy to distin&shy;guish. In a free hour, when our pow&shy;er of choice is un&shy;tram&shy;melled and when noth&shy;ing pre&shy;vents our be&shy;ing able to do what we like best, ev&shy;ery plea&shy;sure is to be wel&shy;comed and ev&shy;ery pain avoid&shy;ed. But in cer&shy;tain cir&shy;cum&shy;s&shy;tances and ow&shy;ing to the claims of du&shy;ty or the obli&shy;ga&shy;tions of busi&shy;ness it will fre&shy;quent&shy;ly oc&shy;cur that plea&shy;sures have to be re&shy;pu&shy;di&shy;at&shy;ed and an&shy;noy&shy;ances ac&shy;cept&shy;ed. The wise man there&shy;fore al&shy;ways holds in th&shy;ese mat&shy;ters to this prin&shy;ci&shy;ple of se&shy;lec&shy;tion: he re&shy;jects plea&shy;sures to se&shy;cure other greater plea&shy;sures, or else he en&shy;dures pains to avoid worse pains.';
  84. $pdf->SetFont('times', '', 10);
  85. $pdf->SetDrawColor(255,0,0);
  86. $pdf->SetTextColor(0,63,127);
  87. // print a cell
  88. $pdf->writeHTMLCell(50, 0, '', '', $html, 1, 1, 0, true, 'J');
  89. // ---------------------------------------------------------
  90. //Close and output PDF document
  91. $pdf->Output('example_046.pdf', 'I');
  92. //============================================================+
  93. // END OF FILE
  94. //============================================================+