Commit 51514e032efba75e9f36b114356230a791953305

Authored by Brian Manning
1 parent 471a2ccf29

table_demo: updated example links

Showing 1 changed file with 2 additions and 8 deletions Inline Diff

#!/usr/bin/env php 1 1 #!/usr/bin/env php
2 2
<?php 3 3 <?php
/** 4 4 /**
* FILENAME: 5 5 * FILENAME:
* pdflib_demo 6 6 * pdflib_demo
* 7 7 *
* DESCRIPTION: 8 8 * DESCRIPTION:
* Demonstration of the pdflib PHP Library for generating PDF files 9 9 * Demonstration of the pdflib PHP Library for generating PDF files
* 10 10 *
*/ 11 11 */
12 12
/** 13 13 /**
Links: 14 14 Links:
- https://www.pdflib.com/developer/technical-documentation/manuals/ 15 15 - https://www.pdflib.com/developer/technical-documentation/manuals/
- https://www.pdflib.com/pdflib-cookbook/browse-all-topics/ 16 16 - https://www.pdflib.com/pdflib-cookbook/browse-all-topics/
- https://www.pdflib.com/pdflib-cookbook/graphics/layers-and-bookmarks/php-layers-and-bookmarks/ 17 17 - https://www.pdflib.com/pdflib-cookbook/tables/starter-table/
- https://www.pdflib.com/pdflib-cookbook/text-output/create-interactive-index/php-create-interactive-index/ 18 18 - https://www.pdflib.com/pdflib-cookbook/tables/vertical-text-alignment/
- https://www.pdflib.com/pdflib-cookbook/general-programming/starter-basic/php-general-progamming-issues/ 19 19 - https://www.pdflib.com/pdflib-cookbook/general-programming/starter-basic/php-general-progamming-issues/
- https://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/linked-textblocks/php-linked-textblocks/ 20
- https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/ 21
- https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/ 22
- https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf 23
- https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ 24
25 20
*/ 26 21 */
27 22
// set a default timezone 28 23 // set a default timezone
date_default_timezone_set("America/Los_Angeles"); 29 24 date_default_timezone_set("America/Los_Angeles");
30 25
//require_once('tcpdf_include.php'); 31 26 //require_once('tcpdf_include.php');
$outfile = __DIR__ . '/pdflib_table_output.pdf'; 32 27 $outfile = __DIR__ . '/pdflib_table_output.pdf';
33 28
// page placement defaults 34 29 // page placement defaults
$pageTopYPortrait = 750; 35 30 $pageTopYPortrait = 750;
$pageTopYLandscape = 570; 36 31 $pageTopYLandscape = 570;
37
38 32
// wrap PDFlib usage in a try{} block 39 33 // wrap PDFlib usage in a try{} block
try { 40 34 try {
$pdf = new PDFlib(); 41 35 $pdf = new PDFlib();
42 36
// set up some PDFlib options 43 37 // set up some PDFlib options
$pdf->set_option("errorpolicy=return"); 44 38 $pdf->set_option("errorpolicy=return");
$pdf->set_option("stringformat=utf8"); 45 39 $pdf->set_option("stringformat=utf8");
46 40
if ($pdf->begin_document($outfile, "") == 0) 47 41 if ($pdf->begin_document($outfile, "") == 0)
throw new Exception("Error: " . $pdf->get_errmsg()); 48 42 throw new Exception("Error: " . $pdf->get_errmsg());
49 43
// set up the document metadata info 50 44 // set up the document metadata info
$pdf->set_info('Creator', 'IODP Science Support Office'); 51 45 $pdf->set_info('Creator', 'IODP Science Support Office');
$pdf->set_info('Author', 'IODP Science Support Office'); 52 46 $pdf->set_info('Author', 'IODP Science Support Office');
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); 53 47 $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals');
$pdf->set_info('Subject', 'IODP Proposals'); 54 48 $pdf->set_info('Subject', 'IODP Proposals');
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); 55 49 $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition');
56 50
$textOpts = "fontname={Helvetica} embedding fontsize=20 " 57 51 $textOpts = "fontname={Helvetica} embedding fontsize=20 "
. "encoding=unicode "; 58 52 . "encoding=unicode ";
59 53
// START PAGE 1 60 54 // START PAGE 1
$pdf->begin_page_ext(612, 792, ''); 61 55 $pdf->begin_page_ext(612, 792, '');
62 56
// create bookmarks first thing 63 57 // create bookmarks first thing
$action = $pdf->create_action("GoTo", "destination={page=1}"); 64 58 $action = $pdf->create_action("GoTo", "destination={page=1}");
$pdf->create_bookmark("Page 1", " action={activate= " . $action . "}"); 65 59 $pdf->create_bookmark("Page 1", " action={activate= " . $action . "}");
66 60
// action 67 61 // action
$action = $pdf->create_action("GoTo", "destination={page=2}"); 68 62 $action = $pdf->create_action("GoTo", "destination={page=2}");
// bookmark 69 63 // bookmark
$pdf->create_bookmark("Page 2", " action={activate= " . $action . "}"); 70 64 $pdf->create_bookmark("Page 2", " action={activate= " . $action . "}");
71 65
72 66
// text/image 73 67 // text/image
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, 74 68 $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750,
$textOpts . " underline=true matchbox={name=to_second_page}"); 75 69 $textOpts . " underline=true matchbox={name=to_second_page}");
// annotation; reuse the "page 2" action above 76 70 // annotation; reuse the "page 2" action above
$optlist = "action={activate " . $action . "} linewidth=0 " . 77 71 $optlist = "action={activate " . $action . "} linewidth=0 " .
"usematchbox={to_second_page}"; 78 72 "usematchbox={to_second_page}";
$pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); 79 73 $pdf->create_annotation(0, 0, 0, 0, "Link", $optlist);
80 74
// the rest of the text on page 1 81 75 // the rest of the text on page 1
$pdf->fit_textline("This is some text on the first page; ", 20, 720, 82 76 $pdf->fit_textline("This is some text on the first page; ", 20, 720,
$textOpts); 83 77 $textOpts);
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); 84 78 $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts);
85 79
// END PAGE 1 86 80 // END PAGE 1
$pdf->end_page_ext(''); 87 81 $pdf->end_page_ext('');
88 82
// START PAGE 2 89 83 // START PAGE 2
//$pdf->begin_page_ext(612, 792, ''); 90 84 //$pdf->begin_page_ext(612, 792, '');
$ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); 91 85 $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", '');
if ($ssfPDF == 0) 92 86 if ($ssfPDF == 0)
throw new Exception("Error: " . $p->get_errmsg()); 93 87 throw new Exception("Error: " . $p->get_errmsg());
94 88
$ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); 95 89 $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, '');
$ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); 96 90 $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width");
$ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); 97 91 $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height");
//print "Page width/height: $ssfWidth x $ssfHeight\n"; 98 92 //print "Page width/height: $ssfWidth x $ssfHeight\n";
99 93
$pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); 100 94 $pdf->begin_page_ext($ssfWidth, $ssfHeight, '');
101 95
$pdf->fit_pdi_page($ssfPage, 0, 0, ''); 102 96 $pdf->fit_pdi_page($ssfPage, 0, 0, '');
$pdf->close_pdi_page($ssfPage); 103 97 $pdf->close_pdi_page($ssfPage);
$pdf->close_pdi_document($ssfPDF); 104 98 $pdf->close_pdi_document($ssfPDF);
105 99
// write some text on to the page 106 100 // write some text on to the page
$action = $pdf->create_action("GoTo", "destination={page=1}"); 107 101 $action = $pdf->create_action("GoTo", "destination={page=1}");