example_020.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. */
  26. // Include the main TCPDF library (search for installation path).
  27. require_once('tcpdf_include.php');
  28. // extend TCPF with custom functions
  29. class MYPDF extends TCPDF {
  30. public function MultiRow($left, $right) {
  31. // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0)
  32. $page_start = $this->getPage();
  33. $y_start = $this->GetY();
  34. // write the left cell
  35. $this->MultiCell(40, 0, $left, 1, 'R', 1, 2, '', '', true, 0);
  36. $page_end_1 = $this->getPage();
  37. $y_end_1 = $this->GetY();
  38. $this->setPage($page_start);
  39. // write the right cell
  40. $this->MultiCell(0, 0, $right, 1, 'J', 0, 1, $this->GetX() ,$y_start, true, 0);
  41. $page_end_2 = $this->getPage();
  42. $y_end_2 = $this->GetY();
  43. // set the new row position by case
  44. if (max($page_end_1,$page_end_2) == $page_start) {
  45. $ynew = max($y_end_1, $y_end_2);
  46. } elseif ($page_end_1 == $page_end_2) {
  47. $ynew = max($y_end_1, $y_end_2);
  48. } elseif ($page_end_1 > $page_end_2) {
  49. $ynew = $y_end_1;
  50. } else {
  51. $ynew = $y_end_2;
  52. }
  53. $this->setPage(max($page_end_1,$page_end_2));
  54. $this->SetXY($this->GetX(),$ynew);
  55. }
  56. }
  57. // create new PDF document
  58. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  59. // set document information
  60. $pdf->SetCreator(PDF_CREATOR);
  61. $pdf->SetAuthor('Nicola Asuni');
  62. $pdf->SetTitle('TCPDF Example 020');
  63. $pdf->SetSubject('TCPDF Tutorial');
  64. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  65. // set default header data
  66. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 020', PDF_HEADER_STRING);
  67. // set header and footer fonts
  68. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  69. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  70. // set default monospaced font
  71. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  72. // set margins
  73. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  74. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  75. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  76. // set auto page breaks
  77. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  78. // set image scale factor
  79. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  80. // set some language-dependent strings (optional)
  81. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  82. require_once(dirname(__FILE__).'/lang/eng.php');
  83. $pdf->setLanguageArray($l);
  84. }
  85. // ---------------------------------------------------------
  86. // set font
  87. $pdf->SetFont('helvetica', '', 20);
  88. // add a page
  89. $pdf->AddPage();
  90. $pdf->Write(0, 'Example of text layout using Multicell()', '', 0, 'L', true, 0, false, false, 0);
  91. $pdf->Ln(5);
  92. $pdf->SetFont('times', '', 9);
  93. //$pdf->SetCellPadding(0);
  94. //$pdf->SetLineWidth(2);
  95. // set color for background
  96. $pdf->SetFillColor(255, 255, 200);
  97. $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.
  98. 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.';
  99. // print some rows just as example
  100. for ($i = 0; $i < 10; ++$i) {
  101. $pdf->MultiRow('Row '.($i+1), $text."\n");
  102. }
  103. // reset pointer to the last page
  104. $pdf->lastPage();
  105. // ---------------------------------------------------------
  106. //Close and output PDF document
  107. $pdf->Output('example_020.pdf', 'I');
  108. //============================================================+
  109. // END OF FILE
  110. //============================================================+