Compare View
Commits (2)
Diff
Showing 2 changed files Inline Diff
pdflib_demo
View file @
78894f9
#!/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/graphics/layers-and-bookmarks/php-layers-and-bookmarks/ | |
- https://www.pdflib.com/pdflib-cookbook/text-output/create-interactive-index/php-create-interactive-index/ | 18 | 18 | - https://www.pdflib.com/pdflib-cookbook/text-output/create-interactive-index/php-create-interactive-index/ | |
- 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 | 20 | - 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/ | 21 | 21 | - 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/ | 22 | 22 | - 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 | 23 | 23 | - 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/ | 24 | 24 | - https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ | |
25 | 25 | |||
*/ | 26 | 26 | */ | |
27 | 27 | |||
// set a default timezone | 28 | 28 | // set a default timezone | |
date_default_timezone_set("America/Los_Angeles"); | 29 | 29 | date_default_timezone_set("America/Los_Angeles"); | |
30 | 30 | |||
//require_once('tcpdf_include.php'); | 31 | 31 | //require_once('tcpdf_include.php'); | |
$outfile = __DIR__ . '/pdflib_output.pdf'; | 32 | 32 | $outfile = __DIR__ . '/pdflib_output.pdf'; | |
33 | 33 | |||
// page placement defaults | 34 | 34 | // page placement defaults | |
$pageTopYPortrait = 750; | 35 | 35 | $pageTopYPortrait = 750; | |
$pageTopYLandscape = 570; | 36 | 36 | $pageTopYLandscape = 570; | |
37 | 37 | |||
38 | 38 | |||
// wrap PDFlib usage in a try{} block | 39 | 39 | // wrap PDFlib usage in a try{} block | |
try { | 40 | 40 | try { | |
$pdf = new PDFlib(); | 41 | 41 | $pdf = new PDFlib(); | |
42 | 42 | |||
// set up some PDFlib options | 43 | 43 | // set up some PDFlib options | |
$pdf->set_option("errorpolicy=return"); | 44 | 44 | $pdf->set_option("errorpolicy=return"); | |
$pdf->set_option("stringformat=utf8"); | 45 | 45 | $pdf->set_option("stringformat=utf8"); | |
46 | 46 | |||
if ($pdf->begin_document($outfile, "") == 0) | 47 | 47 | if ($pdf->begin_document($outfile, "") == 0) | |
throw new Exception("Error: " . $pdf->get_errmsg()); | 48 | 48 | throw new Exception("Error: " . $pdf->get_errmsg()); | |
49 | 49 | |||
// set up the document metadata info | 50 | 50 | // set up the document metadata info | |
$pdf->set_info('Creator', 'IODP Science Support Office'); | 51 | 51 | $pdf->set_info('Creator', 'IODP Science Support Office'); | |
$pdf->set_info('Author', 'IODP Science Support Office'); | 52 | 52 | $pdf->set_info('Author', 'IODP Science Support Office'); | |
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | 53 | 53 | $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | |
$pdf->set_info('Subject', 'IODP Proposals'); | 54 | 54 | $pdf->set_info('Subject', 'IODP Proposals'); | |
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | 55 | 55 | $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | |
56 | 56 | |||
$textOpts = "fontname={Helvetica} embedding fontsize=20 " | 57 | 57 | $textOpts = "fontname={Helvetica} embedding fontsize=20 " | |
. "encoding=unicode "; | 58 | 58 | . "encoding=unicode "; | |
59 | 59 | |||
// START PAGE 1 | 60 | 60 | // START PAGE 1 | |
$pdf->begin_page_ext(612, 792, ''); | 61 | 61 | $pdf->begin_page_ext(612, 792, ''); | |
62 | 62 | |||
// create bookmarks first thing | 63 | 63 | // create bookmarks first thing | |
$action = $pdf->create_action("GoTo", "destination={page=1}"); | 64 | 64 | $action = $pdf->create_action("GoTo", "destination={page=1}"); | |
$pdf->create_bookmark("Page 1", " action={activate= " . $action . "}"); | 65 | 65 | $pdf->create_bookmark("Page 1", " action={activate= " . $action . "}"); | |
66 | 66 | |||
// action | 67 | 67 | // action | |
$action = $pdf->create_action("GoTo", "destination={page=2}"); | 68 | 68 | $action = $pdf->create_action("GoTo", "destination={page=2}"); | |
// bookmark | 69 | 69 | // bookmark | |
$pdf->create_bookmark("Page 2", " action={activate= " . $action . "}"); | 70 | 70 | $pdf->create_bookmark("Page 2", " action={activate= " . $action . "}"); | |
71 | 71 | |||
72 | 72 | |||
// text/image | 73 | 73 | // text/image | |
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | 74 | 74 | $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | |
$textOpts . " underline=true matchbox={name=to_second_page}"); | 75 | 75 | $textOpts . " underline=true matchbox={name=to_second_page}"); | |
// annotation; reuse the "page 2" action above | 76 | 76 | // annotation; reuse the "page 2" action above | |
$optlist = "action={activate " . $action . "} linewidth=0 " . | 77 | 77 | $optlist = "action={activate " . $action . "} linewidth=0 " . | |
"usematchbox={to_second_page}"; | 78 | 78 | "usematchbox={to_second_page}"; | |
$pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | 79 | 79 | $pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | |
80 | 80 | |||
// the rest of the text on page 1 | 81 | 81 | // the rest of the text on page 1 | |
$pdf->fit_textline("This is some text on the first page; ", 20, 720, | 82 | 82 | $pdf->fit_textline("This is some text on the first page; ", 20, 720, | |
$textOpts); | 83 | 83 | $textOpts); | |
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | 84 | 84 | $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | |
85 | 85 | |||
// END PAGE 1 | 86 | 86 | // END PAGE 1 | |
$pdf->end_page_ext(''); | 87 | 87 | $pdf->end_page_ext(''); | |
88 | 88 | |||
// START PAGE 2 | 89 | 89 | // START PAGE 2 | |
//$pdf->begin_page_ext(612, 792, ''); | 90 | 90 | //$pdf->begin_page_ext(612, 792, ''); | |
$ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | 91 | 91 | $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | |
if ($ssfPDF == 0) | 92 | 92 | if ($ssfPDF == 0) | |
throw new Exception("Error: " . $p->get_errmsg()); | 93 | 93 | throw new Exception("Error: " . $p->get_errmsg()); | |
94 | 94 | |||
$ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | 95 | 95 | $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | |
$ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | 96 | 96 | $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | |
$ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | 97 | 97 | $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | |
//print "Page width/height: $ssfWidth x $ssfHeight\n"; | 98 | 98 | //print "Page width/height: $ssfWidth x $ssfHeight\n"; | |
99 | 99 | |||
$pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | 100 | 100 | $pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | |
101 | 101 | |||
$pdf->fit_pdi_page($ssfPage, 0, 0, ''); | 102 | 102 | $pdf->fit_pdi_page($ssfPage, 0, 0, ''); | |
$pdf->close_pdi_page($ssfPage); | 103 | 103 | $pdf->close_pdi_page($ssfPage); | |
$pdf->close_pdi_document($ssfPDF); | 104 | 104 | $pdf->close_pdi_document($ssfPDF); | |
105 | 105 | |||
// write some text on to the page | 106 | 106 | // write some text on to the page | |
// for landscape mode... | 107 | 107 | // for landscape mode... | |
//$pdf->fit_textline("Back to Top", 20, 570, | 108 | 108 | //$pdf->fit_textline("Back to Top", 20, 570, | |
//$linkOpts = linkAttribs(1, 750); | 109 | 109 | //$linkOpts = linkAttribs(1, 750); | |
$action = $pdf->create_action("GoTo", "destination={page=1}"); | 110 | 110 | $action = $pdf->create_action("GoTo", "destination={page=1}"); | |
$pdf->fit_textline("Back to Top", 20, $ssfHeight - 30, | 111 | 111 | $pdf->fit_textline("Back to Top", 20, $ssfHeight - 30, | |
$textOpts . " underline=true matchbox={name=to_first_page}"); | 112 | 112 | $textOpts . " underline=true matchbox={name=to_first_page}"); | |
113 | 113 | |||
// call create_annotation here | 114 | 114 | // call create_annotation here | |
$optlist = "action={activate " . $action . "} linewidth=0 " . | 115 | 115 | $optlist = "action={activate " . $action . "} linewidth=0 " . | |
"usematchbox={to_first_page}"; | 116 | 116 | "usematchbox={to_first_page}"; | |
$pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | 117 | 117 | $pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | |
118 | 118 | |||
// END PAGE 2 | 119 | 119 | // END PAGE 2 | |
$pdf->end_page_ext(''); | 120 | 120 | $pdf->end_page_ext(''); | |
121 | 121 | |||
// close the document | 122 | 122 | // close the document | |
$pdf->end_document(''); | 123 | 123 | $pdf->end_document(''); | |
} | 124 | 124 | } | |
125 | 125 | |||
catch (PDFlibException $e) { | 126 | 126 | catch (PDFlibException $e) { | |
die("PDFlib exception occurred in sample:\n" . | 127 | 127 | die("PDFlib exception occurred in sample:\n" . | |
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . | 128 | 128 | "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . | |
$e->get_errmsg() . "\n"); | 129 | 129 | $e->get_errmsg() . "\n"); | |
} | 130 | 130 | } | |
131 | 131 | |||
catch (Exception $e) { | 132 | 132 | catch (Exception $e) { | |
die($e); | 133 | 133 | die($e); | |
} | 134 | 134 | } | |
135 | 135 | |||
$p = 0; | 136 | 136 | $p = 0; | |
137 | 137 | |||
function linkAttribs($pageNum = 1, $pageY = 750) { | 138 | 138 | function linkAttribs($pageNum = 1, $pageY = 750) { | |
return "destination={page={$pageNum} type=fixed left=0 top={$pageY}}" | 139 | 139 | return "destination={page={$pageNum} type=fixed left=0 top={$pageY}}" | |
. " underline=true"; | 140 | 140 | . " underline=true"; | |
} | 141 | 141 | } | |
142 | 142 | |||
/* | 143 | 143 | /* | |
// write out the contents of the first page | 144 | 144 | // write out the contents of the first page | |
$pdf->AddPage(); | 145 | 145 | $pdf->AddPage(); | |
$topLink = $pdf->AddLink(); | 146 | 146 | $topLink = $pdf->AddLink(); | |
$pdf->SetLink($topLink); | 147 | 147 | $pdf->SetLink($topLink); | |
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); | 148 | 148 | //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); | |
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); | 149 | 149 | $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); | |
//$pdf->SetFont('DejaVu', '', 20); | 150 | 150 | //$pdf->SetFont('DejaVu', '', 20); | |
$pdf->SetFont('dejavusanscondensed', '', 20); | 151 | 151 | $pdf->SetFont('dejavusanscondensed', '', 20); | |
$pdf->SetFont('', 'U'); | 152 | 152 | $pdf->SetFont('', 'U'); |
table_demo
View file @
78894f9
File was created | 1 | #!/usr/bin/env php | ||
2 | ||||
3 | <?php | |||
4 | /** | |||
5 | * FILENAME: | |||
6 | * pdflib_demo | |||
7 | * | |||
8 | * DESCRIPTION: | |||
9 | * Demonstration of the pdflib PHP Library for generating PDF files | |||
10 | * | |||
11 | */ | |||
12 | ||||
13 | /** | |||
14 | Links: | |||
15 | - https://www.pdflib.com/developer/technical-documentation/manuals/ | |||
16 | - https://www.pdflib.com/pdflib-cookbook/browse-all-topics/ | |||
17 | - https://www.pdflib.com/pdflib-cookbook/graphics/layers-and-bookmarks/php-layers-and-bookmarks/ | |||
18 | - https://www.pdflib.com/pdflib-cookbook/text-output/create-interactive-index/php-create-interactive-index/ | |||
19 | - https://www.pdflib.com/pdflib-cookbook/general-programming/starter-basic/php-general-progamming-issues/ | |||
20 | - https://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/linked-textblocks/php-linked-textblocks/ | |||
21 | - https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/ | |||
22 | - https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/ | |||
23 | - https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf | |||
24 | - https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ | |||
25 | ||||
26 | */ | |||
27 | ||||
28 | // set a default timezone | |||
29 | date_default_timezone_set("America/Los_Angeles"); | |||
30 | ||||
31 | //require_once('tcpdf_include.php'); | |||
32 | $outfile = __DIR__ . '/table_output.pdf'; | |||
33 | ||||
34 | // page placement defaults | |||
35 | $pageTopYPortrait = 750; | |||
36 | $pageTopYLandscape = 570; | |||
37 | ||||
38 | ||||
39 | // wrap PDFlib usage in a try{} block | |||
40 | try { | |||
41 | $pdf = new PDFlib(); | |||
42 | ||||
43 | // set up some PDFlib options | |||
44 | $pdf->set_option("errorpolicy=return"); | |||
45 | $pdf->set_option("stringformat=utf8"); | |||
46 | ||||
47 | if ($pdf->begin_document($outfile, "") == 0) | |||
48 | throw new Exception("Error: " . $pdf->get_errmsg()); | |||
49 | ||||
50 | // set up the document metadata info | |||
51 | $pdf->set_info('Creator', 'IODP Science Support Office'); | |||
52 | $pdf->set_info('Author', 'IODP Science Support Office'); | |||
53 | $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | |||
54 | $pdf->set_info('Subject', 'IODP Proposals'); | |||
55 | $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | |||
56 | ||||
57 | $textOpts = "fontname={Helvetica} embedding fontsize=20 " | |||
58 | . "encoding=unicode "; | |||
59 | ||||
60 | // START PAGE 1 | |||
61 | $pdf->begin_page_ext(612, 792, ''); | |||
62 | ||||
63 | // create bookmarks first thing | |||
64 | $action = $pdf->create_action("GoTo", "destination={page=1}"); | |||
65 | $pdf->create_bookmark("Page 1", " action={activate= " . $action . "}"); | |||
66 | ||||
67 | // action | |||
68 | $action = $pdf->create_action("GoTo", "destination={page=2}"); | |||
69 | // bookmark | |||
70 | $pdf->create_bookmark("Page 2", " action={activate= " . $action . "}"); | |||
71 | ||||
72 | ||||
73 | // text/image | |||
74 | $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | |||
75 | $textOpts . " underline=true matchbox={name=to_second_page}"); | |||
76 | // annotation; reuse the "page 2" action above | |||
77 | $optlist = "action={activate " . $action . "} linewidth=0 " . | |||
78 | "usematchbox={to_second_page}"; | |||
79 | $pdf->create_annotation(0, 0, 0, 0, "Link", $optlist); | |||
80 | ||||
81 | // the rest of the text on page 1 | |||
82 | $pdf->fit_textline("This is some text on the first page; ", 20, 720, | |||
83 | $textOpts); | |||
84 | $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | |||
85 | ||||
86 | // END PAGE 1 | |||
87 | $pdf->end_page_ext(''); | |||
88 | ||||
89 | // START PAGE 2 | |||
90 | //$pdf->begin_page_ext(612, 792, ''); | |||
91 | $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | |||
92 | if ($ssfPDF == 0) | |||
93 | throw new Exception("Error: " . $p->get_errmsg()); | |||
94 | ||||
95 | $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | |||
96 | $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | |||
97 | $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | |||
98 | //print "Page width/height: $ssfWidth x $ssfHeight\n"; | |||
99 | ||||
100 | $pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | |||
101 | ||||
102 | $pdf->fit_pdi_page($ssfPage, 0, 0, ''); | |||
103 | $pdf->close_pdi_page($ssfPage); | |||
104 | $pdf->close_pdi_document($ssfPDF); | |||
105 |