Commit 78894f99ac80c6dcbf4610d73771680c6c8e9a86

Authored by Brian Manning
1 parent 19da3db8b7

table_demo: added file

Showing 1 changed file with 136 additions and 0 deletions Inline Diff

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