example_020.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. //============================================================+
  3. // File name : example_020.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2010-08-08
  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 s.r.l.
  16. // Via Della Pace, 11
  17. // 09044 Quartucciu (CA)
  18. // ITALY
  19. // www.tecnick.com
  20. // info@tecnick.com
  21. //============================================================+
  22. /**
  23. * Creates an example PDF TEST document using TCPDF
  24. * @package com.tecnick.tcpdf
  25. * @abstract TCPDF - Example: Two columns composed by MultiCell of different heights
  26. * @author Nicola Asuni
  27. * @since 2008-03-04
  28. */
  29. require_once('../config/lang/eng.php');
  30. require_once('../tcpdf.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
  84. $pdf->setLanguageArray($l);
  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. //============================================================+