Commit 9d13742da44d526a8c4345f94271120cbce777a2
1 parent
001b97d56e
pdflib_demo: added code that should produce links
- Switched back to the portrait SSF from P771 - Added a function `linkAttribs()` that would create the text for setting up attributes for links
Showing 1 changed file with 17 additions and 2 deletions Inline Diff
pdflib_demo
View file @
9d13742
#!/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/general-programming/starter-basic/php-general-progamming-issues/ | 17 | 17 | - 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/ | 18 | 18 | - https://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/linked-textblocks/php-linked-textblocks/ | |
- https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/ | 19 | 19 | - https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/ | |
- https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/ | 20 | 20 | - https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/ | |
- https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf | 21 | 21 | - https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf | |
- https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ | 22 | 22 | - https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ | |
23 | 23 | |||
*/ | 24 | 24 | */ | |
25 | 25 | |||
// set a default timezone | 26 | 26 | // set a default timezone | |
date_default_timezone_set("America/Los_Angeles"); | 27 | 27 | date_default_timezone_set("America/Los_Angeles"); | |
28 | 28 | |||
//require_once('tcpdf_include.php'); | 29 | 29 | //require_once('tcpdf_include.php'); | |
$outfile = __DIR__ . '/output.pdf'; | 30 | 30 | $outfile = __DIR__ . '/output.pdf'; | |
31 | 31 | |||
32 | // page placement defaults | |||
33 | $pageTopYPortrait = 750; | |||
34 | $pageTopYLandscape = 570; | |||
35 | ||||
36 | ||||
// wrap PDFlib usage in a try{} block | 32 | 37 | // wrap PDFlib usage in a try{} block | |
try { | 33 | 38 | try { | |
$pdf = new PDFlib(); | 34 | 39 | $pdf = new PDFlib(); | |
35 | 40 | |||
// set up some PDFlib options | 36 | 41 | // set up some PDFlib options | |
$pdf->set_option("errorpolicy=return"); | 37 | 42 | $pdf->set_option("errorpolicy=return"); | |
$pdf->set_option("stringformat=utf8"); | 38 | 43 | $pdf->set_option("stringformat=utf8"); | |
39 | 44 | |||
if ($pdf->begin_document($outfile, "") == 0) | 40 | 45 | if ($pdf->begin_document($outfile, "") == 0) | |
throw new Exception("Error: " . $pdf->get_errmsg()); | 41 | 46 | throw new Exception("Error: " . $pdf->get_errmsg()); | |
42 | 47 | |||
// set up the document metadata info | 43 | 48 | // set up the document metadata info | |
$pdf->set_info('Creator', 'IODP Science Support Office'); | 44 | 49 | $pdf->set_info('Creator', 'IODP Science Support Office'); | |
$pdf->set_info('Author', 'IODP Science Support Office'); | 45 | 50 | $pdf->set_info('Author', 'IODP Science Support Office'); | |
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | 46 | 51 | $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | |
$pdf->set_info('Subject', 'IODP Proposals'); | 47 | 52 | $pdf->set_info('Subject', 'IODP Proposals'); | |
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | 48 | 53 | $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | |
49 | 54 | |||
// START PAGE 1 | 50 | 55 | // START PAGE 1 | |
$pdf->begin_page_ext(612, 792, ''); | 51 | 56 | $pdf->begin_page_ext(612, 792, ''); | |
52 | 57 | |||
$textOpts = "fontname={Helvetica} embedding fontsize=20 " | 53 | 58 | $textOpts = "fontname={Helvetica} embedding fontsize=20 " | |
. "encoding=unicode "; | 54 | 59 | . "encoding=unicode "; | |
55 | 60 | |||
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | 56 | 61 | $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | |
$textOpts . " underline=true"); | 57 | 62 | $textOpts . " underline=true"); | |
$pdf->fit_textline("This is some text on the first page; ", 20, 720, | 58 | 63 | $pdf->fit_textline("This is some text on the first page; ", 20, 720, | |
$textOpts); | 59 | 64 | $textOpts); | |
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | 60 | 65 | $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | |
61 | 66 | |||
// END PAGE 1 | 62 | 67 | // END PAGE 1 | |
$pdf->end_page_ext(''); | 63 | 68 | $pdf->end_page_ext(''); | |
64 | 69 | |||
// START PAGE 2 | 65 | 70 | // START PAGE 2 | |
//$pdf->begin_page_ext(612, 792, ''); | 66 | 71 | //$pdf->begin_page_ext(612, 792, ''); | |
$ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | 67 | 72 | $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | |
if ($ssfPDF == 0) | 68 | 73 | if ($ssfPDF == 0) | |
throw new Exception("Error: " . $p->get_errmsg()); | 69 | 74 | throw new Exception("Error: " . $p->get_errmsg()); | |
70 | 75 | |||
$ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | 71 | 76 | $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | |
$ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | 72 | 77 | $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | |
$ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | 73 | 78 | $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | |
74 | 79 | |||
$pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | 75 | 80 | $pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | |
76 | 81 | |||
$pdf->fit_pdi_page($ssfPage, 0, 0, ''); | 77 | 82 | $pdf->fit_pdi_page($ssfPage, 0, 0, ''); | |
$pdf->close_pdi_page($ssfPage); | 78 | 83 | $pdf->close_pdi_page($ssfPage); | |
$pdf->close_pdi_document($ssfPDF); | 79 | 84 | $pdf->close_pdi_document($ssfPDF); | |
80 | 85 | |||
// write some text on to the page | 81 | 86 | // write some text on to the page | |
$pdf->fit_textline("Back to Top", 20, 570, | 82 | 87 | // for landscape mode... | |
$textOpts . " underline=true"); | 83 | 88 | //$pdf->fit_textline("Back to Top", 20, 570, | |
89 | //$linkOpts = linkAttribs(1, 750); | |||
90 | $optList = "destination={page=1 type=fixed left=0 top=750}"; | |||
91 | $action = $p->create_action("GoTo", $optList); | |||
92 | print_r($linkOpts); | |||
93 | $pdf->fit_textline("Back to Top", 20, 750, $linkOpts); | |||
84 | 94 | |||
// END PAGE 2 | 85 | 95 | // END PAGE 2 | |
$pdf->end_page_ext(''); | 86 | 96 | $pdf->end_page_ext(''); | |
87 | 97 | |||
// close the document | 88 | 98 | // close the document | |
$pdf->end_document(''); | 89 | 99 | $pdf->end_document(''); | |
90 | 100 | |||
} | 91 | 101 | } | |
92 | 102 | |||
catch (PDFlibException $e) { | 93 | 103 | catch (PDFlibException $e) { | |
die("PDFlib exception occurred in sample:\n" . | 94 | 104 | die("PDFlib exception occurred in sample:\n" . | |
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . | 95 | 105 | "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . | |
$e->get_errmsg() . "\n"); | 96 | 106 | $e->get_errmsg() . "\n"); | |
} | 97 | 107 | } | |
98 | 108 | |||
catch (Exception $e) { | 99 | 109 | catch (Exception $e) { | |
die($e); | 100 | 110 | die($e); | |
} | 101 | 111 | } | |
102 | 112 | |||
$p = 0; | 103 | 113 | $p = 0; | |
114 | ||||
115 | function linkAttribs($pageNum = 1, $pageY = 750) { | |||
116 | return "destination={page={$pageNum} type=fixed left=0 top={$pageY}}" | |||
117 | . " underline=true"; | |||
118 | } | |||
104 | 119 | |||
/* | 105 | 120 | /* | |
// write out the contents of the first page | 106 | 121 | // write out the contents of the first page | |
$pdf->AddPage(); | 107 | 122 | $pdf->AddPage(); | |
$topLink = $pdf->AddLink(); | 108 | 123 | $topLink = $pdf->AddLink(); | |
$pdf->SetLink($topLink); | 109 | 124 | $pdf->SetLink($topLink); | |
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); | 110 | 125 | //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); | |
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); | 111 | 126 | $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); | |
//$pdf->SetFont('DejaVu', '', 20); | 112 | 127 | //$pdf->SetFont('DejaVu', '', 20); | |
$pdf->SetFont('dejavusanscondensed', '', 20); | 113 | 128 | $pdf->SetFont('dejavusanscondensed', '', 20); | |
$pdf->SetFont('', 'U'); | 114 | 129 | $pdf->SetFont('', 'U'); | |
$ssfLink = $pdf->AddLink(); | 115 | 130 | $ssfLink = $pdf->AddLink(); | |
$pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); | 116 | 131 | $pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); | |
$pdf->SetFont(''); | 117 | 132 | $pdf->SetFont(''); | |
$pdf->Ln(); | 118 | 133 | $pdf->Ln(); | |
$pdf->Write(10, "This is some text on the first page; "); | 119 | 134 | $pdf->Write(10, "This is some text on the first page; "); | |
$pdf->Ln(); | 120 | 135 | $pdf->Ln(); | |
$pdf->Write(10, "Привет! Этот немного текста."); | 121 | 136 | $pdf->Write(10, "Привет! Этот немного текста."); | |
122 | 137 |