example_026.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. //============================================================+
  3. // File name : example_026.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 026 for TCPDF class
  8. // Text Rendering Modes and Text Clipping
  9. //
  10. // Author: Nicola Asuni
  11. //
  12. // (c) Copyright:
  13. // Nicola Asuni
  14. // Tecnick.com LTD
  15. // www.tecnick.com
  16. // info@tecnick.com
  17. //============================================================+
  18. /**
  19. * Creates an example PDF TEST document using TCPDF
  20. * @package com.tecnick.tcpdf
  21. * @abstract TCPDF - Example: Text Rendering Modes and Text Clipping
  22. * @author Nicola Asuni
  23. * @since 2008-03-04
  24. * @group pdf
  25. */
  26. // Include the main TCPDF library (search for installation path).
  27. require_once('tcpdf_include.php');
  28. // create new PDF document
  29. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  30. // set document information
  31. $pdf->setCreator(PDF_CREATOR);
  32. $pdf->setAuthor('Nicola Asuni');
  33. $pdf->setTitle('TCPDF Example 026');
  34. $pdf->setSubject('TCPDF Tutorial');
  35. $pdf->setKeywords('TCPDF, PDF, example, test, guide');
  36. // set default header data
  37. $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 026', PDF_HEADER_STRING);
  38. // set header and footer fonts
  39. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  40. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  41. // set default monospaced font
  42. $pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  43. // set margins
  44. $pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  45. $pdf->setHeaderMargin(PDF_MARGIN_HEADER);
  46. $pdf->setFooterMargin(PDF_MARGIN_FOOTER);
  47. // set auto page breaks
  48. $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  49. // set image scale factor
  50. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  51. // set some language-dependent strings (optional)
  52. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  53. require_once(dirname(__FILE__).'/lang/eng.php');
  54. $pdf->setLanguageArray($l);
  55. }
  56. // ---------------------------------------------------------
  57. // set font
  58. $pdf->setFont('helvetica', '', 22);
  59. // add a page
  60. $pdf->AddPage();
  61. // set color for text stroke
  62. $pdf->setDrawColor(255,0,0);
  63. $pdf->setTextRenderingMode($stroke=0, $fill=true, $clip=false);
  64. $pdf->Write(0, 'Fill text', '', 0, '', true, 0, false, false, 0);
  65. $pdf->setTextRenderingMode($stroke=0.2, $fill=false, $clip=false);
  66. $pdf->Write(0, 'Stroke text', '', 0, '', true, 0, false, false, 0);
  67. $pdf->setTextRenderingMode($stroke=0.2, $fill=true, $clip=false);
  68. $pdf->Write(0, 'Fill, then stroke text', '', 0, '', true, 0, false, false, 0);
  69. $pdf->setTextRenderingMode($stroke=0, $fill=false, $clip=false);
  70. $pdf->Write(0, 'Neither fill nor stroke text (invisible)', '', 0, '', true, 0, false, false, 0);
  71. // * * * CLIPPING MODES * * * * * * * * * * * * * * * * * *
  72. $pdf->StartTransform();
  73. $pdf->setTextRenderingMode($stroke=0, $fill=true, $clip=true);
  74. $pdf->Write(0, 'Fill text and add to path for clipping', '', 0, '', true, 0, false, false, 0);
  75. $pdf->Image('images/image_demo.jpg', 15, 65, 170, 10, '', '', '', true, 72);
  76. $pdf->StopTransform();
  77. $pdf->StartTransform();
  78. $pdf->setTextRenderingMode($stroke=0.3, $fill=false, $clip=true);
  79. $pdf->Write(0, 'Stroke text and add to path for clipping', '', 0, '', true, 0, false, false, 0);
  80. $pdf->Image('images/image_demo.jpg', 15, 75, 170, 10, '', '', '', true, 72);
  81. $pdf->StopTransform();
  82. $pdf->StartTransform();
  83. $pdf->setTextRenderingMode($stroke=0.3, $fill=true, $clip=true);
  84. $pdf->Write(0, 'Fill, then stroke text and add to path for clipping', '', 0, '', true, 0, false, false, 0);
  85. $pdf->Image('images/image_demo.jpg', 15, 85, 170, 10, '', '', '', true, 72);
  86. $pdf->StopTransform();
  87. $pdf->StartTransform();
  88. $pdf->setTextRenderingMode($stroke=0, $fill=false, $clip=true);
  89. $pdf->Write(0, 'Add text to path for clipping', '', 0, '', true, 0, false, false, 0);
  90. $pdf->Image('images/image_demo.jpg', 15, 95, 170, 10, '', '', '', true, 72);
  91. $pdf->StopTransform();
  92. // reset text rendering mode
  93. $pdf->setTextRenderingMode($stroke=0, $fill=true, $clip=false);
  94. // * * * HTML MODE * * * * * * * * * * * * * * * * * * * * *
  95. // The following attributes were added to HTML:
  96. // stroke : stroke width
  97. // strokecolor : stroke color
  98. // fill : true (default) to fill the font, false otherwise
  99. // create some HTML content with text rendering modes
  100. $html = '<span stroke="0" fill="true">HTML Fill text</span><br />';
  101. $html .= '<span stroke="0.2" fill="false">HTML Stroke text</span><br />';
  102. $html .= '<span stroke="0.2" fill="true" strokecolor="#FF0000" color="#FFFF00">HTML Fill, then stroke text</span><br />';
  103. $html .= '<span stroke="0" fill="false">HTML Neither fill nor stroke text (invisible)</span><br />';
  104. // output the HTML content
  105. $pdf->writeHTML($html, true, 0, true, 0);
  106. // ---------------------------------------------------------
  107. //Close and output PDF document
  108. $pdf->Output('example_026.pdf', 'I');
  109. //============================================================+
  110. // END OF FILE
  111. //============================================================+