example_020.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. //============================================================+
  3. // File name : example_020.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 020 for TCPDF class
  8. // Two columns composed by MultiCell of different
  9. // heights
  10. //
  11. // Author: Nicola Asuni
  12. //
  13. // (c) Copyright:
  14. // Nicola Asuni
  15. // Tecnick.com LTD
  16. // www.tecnick.com
  17. // info@tecnick.com
  18. //============================================================+
  19. /**
  20. * Creates an example PDF TEST document using TCPDF
  21. * @package com.tecnick.tcpdf
  22. * @abstract TCPDF - Example: Two columns composed by MultiCell of different heights
  23. * @author Nicola Asuni
  24. * @since 2008-03-04
  25. * @group cell
  26. * @group column
  27. * @group pdf
  28. */
  29. // Include the main TCPDF library (search for installation path).
  30. require_once('tcpdf_include.php');
  31. // extend TCPF with custom functions
  32. class MYPDF extends TCPDF {
  33. public function MultiRow($left, $right) {
  34. // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0)
  35. $page_start = $this->getPage();
  36. $y_start = $this->GetY();
  37. // write the left cell
  38. $this->MultiCell(40, 0, $left, 1, 'R', 1, 2, '', '', true, 0);
  39. $page_end_1 = $this->getPage();
  40. $y_end_1 = $this->GetY();
  41. $this->setPage($page_start);
  42. // write the right cell
  43. $this->MultiCell(0, 0, $right, 1, 'J', 0, 1, $this->GetX() ,$y_start, true, 0);
  44. $page_end_2 = $this->getPage();
  45. $y_end_2 = $this->GetY();
  46. // set the new row position by case
  47. if (max($page_end_1,$page_end_2) == $page_start) {
  48. $ynew = max($y_end_1, $y_end_2);
  49. } elseif ($page_end_1 == $page_end_2) {
  50. $ynew = max($y_end_1, $y_end_2);
  51. } elseif ($page_end_1 > $page_end_2) {
  52. $ynew = $y_end_1;
  53. } else {
  54. $ynew = $y_end_2;
  55. }
  56. $this->setPage(max($page_end_1,$page_end_2));
  57. $this->setXY($this->GetX(),$ynew);
  58. }
  59. }
  60. // create new PDF document
  61. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  62. // set document information
  63. $pdf->setCreator(PDF_CREATOR);
  64. $pdf->setAuthor('Nicola Asuni');
  65. $pdf->setTitle('TCPDF Example 020');
  66. $pdf->setSubject('TCPDF Tutorial');
  67. $pdf->setKeywords('TCPDF, PDF, example, test, guide');
  68. // set default header data
  69. $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 020', PDF_HEADER_STRING);
  70. // set header and footer fonts
  71. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  72. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  73. // set default monospaced font
  74. $pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  75. // set margins
  76. $pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  77. $pdf->setHeaderMargin(PDF_MARGIN_HEADER);
  78. $pdf->setFooterMargin(PDF_MARGIN_FOOTER);
  79. // set auto page breaks
  80. $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  81. // set image scale factor
  82. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  83. // set some language-dependent strings (optional)
  84. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  85. require_once(dirname(__FILE__).'/lang/eng.php');
  86. $pdf->setLanguageArray($l);
  87. }
  88. // ---------------------------------------------------------
  89. // set font
  90. $pdf->setFont('helvetica', '', 20);
  91. // add a page
  92. $pdf->AddPage();
  93. $pdf->Write(0, 'Example of text layout using Multicell()', '', 0, 'L', true, 0, false, false, 0);
  94. $pdf->Ln(5);
  95. $pdf->setFont('times', '', 9);
  96. //$pdf->setCellPadding(0);
  97. //$pdf->setLineWidth(2);
  98. // set color for background
  99. $pdf->setFillColor(255, 255, 200);
  100. $text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed imperdiet lectus. Phasellus quis velit velit, non condimentum quam. Sed neque urna, ultrices ac volutpat vel, laoreet vitae augue. Sed vel velit erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras eget velit nulla, eu sagittis elit. Nunc ac arcu est, in lobortis tellus. Praesent condimentum rhoncus sodales. In hac habitasse platea dictumst. Proin porta eros pharetra enim tincidunt dignissim nec vel dolor. Cras sapien elit, ornare ac dignissim eu, ultricies ac eros. Maecenas augue magna, ultrices a congue in, mollis eu nulla. Nunc venenatis massa at est eleifend faucibus. Vivamus sed risus lectus, nec interdum nunc.
  101. Fusce et felis vitae diam lobortis sollicitudin. Aenean tincidunt accumsan nisi, id vehicula quam laoreet elementum. Phasellus egestas interdum erat, et viverra ipsum ultricies ac. Praesent sagittis augue at augue volutpat eleifend. Cras nec orci neque. Mauris bibendum posuere blandit. Donec feugiat mollis dui sit amet pellentesque. Sed a enim justo. Donec tincidunt, nisl eget elementum aliquam, odio ipsum ultrices quam, eu porttitor ligula urna at lorem. Donec varius, eros et convallis laoreet, ligula tellus consequat felis, ut ornare metus tellus sodales velit. Duis sed diam ante. Ut rutrum malesuada massa, vitae consectetur ipsum rhoncus sed. Suspendisse potenti. Pellentesque a congue massa.';
  102. // print some rows just as example
  103. for ($i = 0; $i < 10; ++$i) {
  104. $pdf->MultiRow('Row '.($i+1), $text."\n");
  105. }
  106. // reset pointer to the last page
  107. $pdf->lastPage();
  108. // ---------------------------------------------------------
  109. //Close and output PDF document
  110. $pdf->Output('example_020.pdf', 'I');
  111. //============================================================+
  112. // END OF FILE
  113. //============================================================+