example_015.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. //============================================================+
  3. // File name : example_015.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2011-04-15
  6. //
  7. // Description : Example 015 for TCPDF class
  8. // Bookmarks (Table of Content)
  9. // and Named Destinations.
  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: Bookmarks (Table of Content)
  26. * @author Nicola Asuni
  27. * @since 2008-03-04
  28. */
  29. require_once('../config/lang/eng.php');
  30. require_once('../tcpdf.php');
  31. // create new PDF document
  32. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  33. // set document information
  34. $pdf->SetCreator(PDF_CREATOR);
  35. $pdf->SetAuthor('Nicola Asuni');
  36. $pdf->SetTitle('TCPDF Example 015');
  37. $pdf->SetSubject('TCPDF Tutorial');
  38. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  39. // set default header data
  40. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 015', PDF_HEADER_STRING);
  41. // set header and footer fonts
  42. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  43. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  44. // set default monospaced font
  45. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  46. //set margins
  47. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  48. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  49. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  50. //set auto page breaks
  51. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  52. //set image scale factor
  53. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  54. //set some language-dependent strings
  55. $pdf->setLanguageArray($l);
  56. // ---------------------------------------------------------
  57. // Bookmark($txt, $level=0, $y=-1, $page='', $style='', $color=array(0,0,0))
  58. // set font
  59. $pdf->SetFont('times', 'B', 20);
  60. // add a page
  61. $pdf->AddPage();
  62. // set a bookmark for the current position
  63. $pdf->Bookmark('Chapter 1', 0, 0, '', 'B', array(0,64,128));
  64. // print a line using Cell()
  65. $pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
  66. $pdf->SetFont('times', 'I', 14);
  67. $pdf->Write(0, 'You can set PDF Bookmarks using the Bookmark() method.
  68. You can set PDF Named Destinations using the setDestination() method.');
  69. $pdf->SetFont('times', 'B', 20);
  70. // add other pages and bookmarks
  71. $pdf->AddPage();
  72. $pdf->Bookmark('Paragraph 1.1', 1, 0, '', '', array(0,0,0));
  73. $pdf->Cell(0, 10, 'Paragraph 1.1', 0, 1, 'L');
  74. $pdf->AddPage();
  75. $pdf->Bookmark('Paragraph 1.2', 1, 0, '', '', array(0,0,0));
  76. $pdf->Cell(0, 10, 'Paragraph 1.2', 0, 1, 'L');
  77. $pdf->AddPage();
  78. $pdf->Bookmark('Sub-Paragraph 1.2.1', 2, 0, '', 'I', array(0,0,0));
  79. $pdf->Cell(0, 10, 'Sub-Paragraph 1.2.1', 0, 1, 'L');
  80. $pdf->AddPage();
  81. $pdf->Bookmark('Paragraph 1.3', 1, 0, '', '', array(0,0,0));
  82. $pdf->Cell(0, 10, 'Paragraph 1.3', 0, 1, 'L');
  83. $pdf->AddPage();
  84. // add a named destination so you can open this document at this page using the link: "example_015.pdf#chapter2"
  85. $pdf->setDestination('chapter2', 0, '');
  86. $pdf->Bookmark('Chapter 2', 0, 0, '', 'BI', array(128,0,0));
  87. $pdf->Cell(0, 10, 'Chapter 2', 0, 1, 'L');
  88. $pdf->SetFont('times', 'I', 14);
  89. $pdf->Write(0, 'Once saved, you can open this document at this page using the link: "example_015.pdf#chapter2".');
  90. $pdf->AddPage();
  91. $pdf->setDestination('chapter3', 0, '');
  92. $pdf->SetFont('times', 'B', 20);
  93. $pdf->Bookmark('Chapter 3', 0, 0, '', 'B', array(0,64,128));
  94. $pdf->Cell(0, 10, 'Chapter 3', 0, 1, 'L');
  95. $pdf->AddPage();
  96. $pdf->setDestination('chapter4', 0, '');
  97. $pdf->SetFont('times', 'B', 20);
  98. $pdf->Bookmark('Chapter 4', 0, 0, '', 'B', array(0,64,128));
  99. $pdf->Cell(0, 10, 'Chapter 4', 0, 1, 'L');
  100. // ---------------------------------------------------------
  101. //Close and output PDF document
  102. $pdf->Output('example_015.pdf', 'I');
  103. //============================================================+
  104. // END OF FILE
  105. //============================================================+