Compare View
Commits (2)
Diff
Showing 1 changed file Inline Diff
table_demo
View file @
ab54ad1
#!/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/tables/starter-table/ | 17 | 17 | - https://www.pdflib.com/pdflib-cookbook/tables/starter-table/ | |
- https://www.pdflib.com/pdflib-cookbook/tables/vertical-text-alignment/ | 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/ | |
20 | 20 | |||
*/ | 21 | 21 | */ | |
22 | 22 | |||
// set a default timezone | 23 | 23 | // set a default timezone | |
date_default_timezone_set("America/Los_Angeles"); | 24 | 24 | date_default_timezone_set("America/Los_Angeles"); | |
25 | 25 | |||
//require_once('tcpdf_include.php'); | 26 | 26 | //require_once('tcpdf_include.php'); | |
$outfile = __DIR__ . '/pdflib_table_output.pdf'; | 27 | 27 | $outfile = __DIR__ . '/pdflib_table_output.pdf'; | |
28 | 28 | |||
// page placement defaults | 29 | 29 | // page placement defaults | |
$pageTopYPortrait = 750; | 30 | 30 | $pageTopYPortrait = 750; | |
$pageTopYLandscape = 570; | 31 | 31 | $pageTopYLandscape = 570; | |
32 | 32 | |||
// wrap PDFlib usage in a try{} block | 33 | 33 | // wrap PDFlib usage in a try{} block | |
try { | 34 | 34 | try { | |
$pdf = new PDFlib(); | 35 | 35 | $pdf = new PDFlib(); | |
36 | 36 | |||
// set up some PDFlib options | 37 | 37 | // set up some PDFlib options | |
$pdf->set_option("errorpolicy=return"); | 38 | 38 | $pdf->set_option("errorpolicy=return"); | |
$pdf->set_option("stringformat=utf8"); | 39 | 39 | $pdf->set_option("stringformat=utf8"); | |
40 | // all paths in 'searchpath' need to be inside curly braces | |||
41 | // multiple curly-braced paths in $searchpath need to be separated with | |||
42 | // space characters | |||
43 | $searchpath = '{/usr/share/fonts/dejavu/}{' . __DIR__ . '/fonts}'; | |||
44 | $pdf->set_option("searchpath={" . $searchpath . "}"); | |||
// all paths in 'searchpath' need to be inside curly braces | 40 | 45 | ||
// multiple curly-braced paths in $searchpath need to be separated with | 41 | 46 | if ($pdf->begin_document($outfile, "") == 0) | |
// space characters | 42 | 47 | throw new Exception("Error: " . $pdf->get_errmsg()); | |
$searchpath = '{/usr/share/fonts/dejavu/}{' . __DIR__ . '/fonts}'; | 43 | 48 | ||
$pdf->set_option("searchpath={" . $searchpath . "}"); | 44 | 49 | // set up the document metadata info | |
45 | 50 | $pdf->set_info('Creator', 'IODP Science Support Office'); | ||
if ($pdf->begin_document($outfile, "") == 0) | 46 | 51 | $pdf->set_info('Author', 'IODP Science Support Office'); | |
throw new Exception("Error: " . $pdf->get_errmsg()); | 47 | 52 | $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | |
48 | 53 | $pdf->set_info('Subject', 'IODP Proposals'); | ||
// set up the document metadata info | 49 | 54 | $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | |
$pdf->set_info('Creator', 'IODP Science Support Office'); | 50 | 55 | ||
$pdf->set_info('Author', 'IODP Science Support Office'); | 51 | 56 | $textOpts = "fontname={FreeSans} embedding fontsize=20 " | |
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | 52 | 57 | . "encoding=unicode "; | |
$pdf->set_info('Subject', 'IODP Proposals'); | 53 | 58 | ||
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | 54 | 59 | // START PAGE 1 | |
55 | 60 | $pdf->begin_page_ext(0, 0, 'width=letter.width, height=letter.height'); | ||
$textOpts = "fontname={FreeSans} embedding fontsize=20 " | 56 | 61 | ||
. "encoding=unicode "; | 57 | 62 | // create bookmarks first thing | |
58 | 63 | $action = $pdf->create_action("GoTo", "destination={page=1}"); | ||
// START PAGE 1 | 59 | 64 | $pdf->create_bookmark("Page 1", " action={activate= " . $action . "}"); | |
$pdf->begin_page_ext(612, 792, ''); | 60 | 65 | ||
61 | 66 | // action | ||
// create bookmarks first thing | 62 | 67 | $action = $pdf->create_action("GoTo", "destination={page=2}"); | |
$action = $pdf->create_action("GoTo", "destination={page=1}"); | 63 | 68 | // bookmark | |
$pdf->create_bookmark("Page 1", " action={activate= " . $action . "}"); | 64 | 69 | $pdf->create_bookmark("Page 2", " action={activate= " . $action . "}"); | |
65 | 70 | |||
// action | 66 | |||
$action = $pdf->create_action("GoTo", "destination={page=2}"); | 67 | 71 | // text/image | |
// bookmark | 68 | 72 | $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | |
$pdf->create_bookmark("Page 2", " action={activate= " . $action . "}"); | 69 | 73 | $textOpts . " underline=true matchbox={name=to_second_page}"); | |
70 | 74 | // annotation; reuse the "page 2" action above | ||
// text/image | 71 | 75 | $optlist = "action={activate " . $action . "} linewidth=0 " . | |
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | 72 | 76 | "usematchbox={to_second_page}"; | |
$textOpts . " underline=true matchbox={name=to_second_page}"); | 73 | 77 | $pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | |
// annotation; reuse the "page 2" action above | 74 | 78 | ||
$optlist = "action={activate " . $action . "} linewidth=0 " . | 75 | 79 | // the rest of the text on page 1 | |
"usematchbox={to_second_page}"; | 76 | 80 | $pdf->fit_textline("This is some text on the first page; ", 20, 720, | |
$pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | 77 | 81 | $textOpts); | |
78 | 82 | $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | ||
// the rest of the text on page 1 | 79 | 83 | ||
$pdf->fit_textline("This is some text on the first page; ", 20, 720, | 80 | 84 | // END PAGE 1 | |
$textOpts); | 81 | 85 | $pdf->end_page_ext(''); | |
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | 82 | 86 | ||
83 | 87 | // START PAGE 2 | ||
// END PAGE 1 | 84 | 88 | //$pdf->begin_page_ext(612, 792, ''); | |
$pdf->end_page_ext(''); | 85 | 89 | $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | |
86 | 90 | if ($ssfPDF == 0) | ||
// START PAGE 2 | 87 | 91 | throw new Exception("Error: " . $p->get_errmsg()); | |
//$pdf->begin_page_ext(612, 792, ''); | 88 | 92 | ||
$ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | 89 | 93 | $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | |
if ($ssfPDF == 0) | 90 | 94 | $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | |
throw new Exception("Error: " . $p->get_errmsg()); | 91 | 95 | $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | |
92 | 96 | //print "Page width/height: $ssfWidth x $ssfHeight\n"; | ||
$ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | 93 | 97 | ||
$ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | 94 | 98 | $pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | |
$ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | 95 | 99 | ||
//print "Page width/height: $ssfWidth x $ssfHeight\n"; | 96 | 100 | $pdf->fit_pdi_page($ssfPage, 0, 0, ''); | |
97 | 101 | $pdf->close_pdi_page($ssfPage); | ||
$pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | 98 | 102 | $pdf->close_pdi_document($ssfPDF); | |
99 | 103 | |||
$pdf->fit_pdi_page($ssfPage, 0, 0, ''); | 100 | 104 | // write some text on to the page | |
105 | // for landscape mode... | |||
106 | //$pdf->fit_textline("Back to Top", 20, 570, | |||
107 | //$linkOpts = linkAttribs(1, 750); | |||
$pdf->close_pdi_page($ssfPage); | 101 | 108 | $action = $pdf->create_action("GoTo", "destination={page=1}"); | |
$pdf->close_pdi_document($ssfPDF); | 102 | 109 | $pdf->fit_textline("Back to Top", 20, $ssfHeight - 30, | |
103 | 110 | $textOpts . " underline=true matchbox={name=to_first_page}"); | ||
// write some text on to the page | 104 | 111 | ||
// for landscape mode... | 105 | 112 | // call create_annotation here | |
//$pdf->fit_textline("Back to Top", 20, 570, | 106 | 113 | $optlist = "action={activate " . $action . "} linewidth=0 " . | |
//$linkOpts = linkAttribs(1, 750); | 107 | 114 | "usematchbox={to_first_page}"; | |
$action = $pdf->create_action("GoTo", "destination={page=1}"); | 108 | 115 | $pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | |
$pdf->fit_textline("Back to Top", 20, $ssfHeight - 30, | 109 | 116 | ||
$textOpts . " underline=true matchbox={name=to_first_page}"); | 110 | 117 | // END PAGE 2 | |
111 | 118 | $pdf->end_page_ext(''); | ||
// call create_annotation here | 112 | 119 | ||
$optlist = "action={activate " . $action . "} linewidth=0 " . | 113 | 120 | // START PAGE 3 | |
"usematchbox={to_first_page}"; | 114 | 121 | $pdf->begin_page_ext(0, 0, 'width=letter.width, height=letter.height'); | |
$pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | 115 | 122 | ||
116 | 123 | // END PAGE 3 | ||
// END PAGE 2 | 117 | 124 | $pdf->end_page_ext(''); | |
$pdf->end_page_ext(''); | 118 | 125 |