You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.5 KiB

  1. <?php
  2. //============================================================+
  3. // File name : example_015.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  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 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: Bookmarks (Table of Content)
  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. // 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 015');
  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.' 015', 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. // 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. // add a bookmark that points to a named destination
  87. $pdf->Bookmark('Chapter 2', 0, 0, '', 'BI', array(128,0,0), -1, '#chapter2');
  88. $pdf->Cell(0, 10, 'Chapter 2', 0, 1, 'L');
  89. $pdf->SetFont('times', 'I', 14);
  90. $pdf->Write(0, 'Once saved, you can open this document at this page using the link: "example_015.pdf#chapter2".');
  91. $pdf->AddPage();
  92. $pdf->setDestination('chapter3', 0, '');
  93. $pdf->SetFont('times', 'B', 20);
  94. $pdf->Bookmark('Chapter 3', 0, 0, '', 'B', array(0,64,128));
  95. $pdf->Cell(0, 10, 'Chapter 3', 0, 1, 'L');
  96. $pdf->AddPage();
  97. $pdf->setDestination('chapter4', 0, '');
  98. $pdf->SetFont('times', 'B', 20);
  99. $pdf->Bookmark('Chapter 4', 0, 0, '', 'B', array(0,64,128));
  100. $pdf->Cell(0, 10, 'Chapter 4', 0, 1, 'L');
  101. $pdf->AddPage();
  102. $pdf->Bookmark('Chapter 5', 0, 0, '', 'B', array(0,128,0));
  103. $pdf->Cell(0, 10, 'Chapter 5', 0, 1, 'L');
  104. $txt = 'Example of File Attachment.
  105. Double click on the icon to open the attached file.';
  106. $pdf->SetFont('helvetica', '', 10);
  107. $pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);
  108. // attach an external file TXT file
  109. $pdf->Annotation(20, 50, 5, 5, 'TXT file', array('Subtype'=>'FileAttachment', 'Name' => 'PushPin', 'FS' => 'data/utf8test.txt'));
  110. // attach an external file
  111. $pdf->Annotation(50, 50, 5, 5, 'PDF file', array('Subtype'=>'FileAttachment', 'Name' => 'PushPin', 'FS' => 'example_012.pdf'));
  112. // add a bookmark that points to an embedded file
  113. // NOTE: prefix the file name with the * character for generic file and with % character for PDF file
  114. $pdf->Bookmark('TXT file', 0, 0, '', 'B', array(128,0,255), -1, '*utf8test.txt');
  115. // add a bookmark that points to an embedded file
  116. // NOTE: prefix the file name with the * character for generic file and with % character for PDF file
  117. $pdf->Bookmark('PDF file', 0, 0, '', 'B', array(128,0,255), -1, '%example_012.pdf');
  118. // add a bookmark that points to an external URL
  119. $pdf->Bookmark('External URL', 0, 0, '', 'B', array(0,0,255), -1, 'http://www.tcpdf.org');
  120. // ---------------------------------------------------------
  121. //Close and output PDF document
  122. $pdf->Output('example_015.pdf', 'D');
  123. //============================================================+
  124. // END OF FILE
  125. //============================================================+