Commit 5e8f70d56a145f82f15955c198d4424a99d9fb72
1 parent
8abb8dc763
pdflib_demo: load SSF PDF into 2nd page for demo
Showing 1 changed file with 24 additions and 3 deletions Inline Diff
pdflib_demo
View file @
5e8f70d
#!/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/ | |
17 | - https://www.pdflib.com/pdflib-cookbook/general-programming/starter-basic/php-general-progamming-issues/ | |||
18 | - https://www.pdflib.com/en/pdflib-cookbook/block-handling-and-pps/linked-textblocks/php-linked-textblocks/ | |||
19 | - https://www.pdflib.com/pdflib-cookbook/interactive-elements/link-annotations/php-link-annotations/ | |||
20 | - https://www.pdflib.com/pdflib-cookbook/text-output/footnotes-in-text/footnotes-in-text/ | |||
21 | - https://www.pdflib.com/fileadmin/pdflib/Cookbook/pdf/footnotes_in_text.pdf | |||
22 | - https://www.pdflib.com/pdflib-cookbook/pdf-import/import-in-reverse-order/php-import-in-reverse-order/ | |||
17 | 23 | |||
*/ | 18 | 24 | */ | |
19 | 25 | |||
// set a default timezone | 20 | 26 | // set a default timezone | |
date_default_timezone_set("America/Los_Angeles"); | 21 | 27 | date_default_timezone_set("America/Los_Angeles"); | |
22 | 28 | |||
//require_once('tcpdf_include.php'); | 23 | 29 | //require_once('tcpdf_include.php'); | |
$outfile = __DIR__ . '/output.pdf'; | 24 | 30 | $outfile = __DIR__ . '/output.pdf'; | |
25 | 31 | |||
// wrap PDFlib usage in a try{} block | 26 | 32 | // wrap PDFlib usage in a try{} block | |
try { | 27 | 33 | try { | |
$pdf = new PDFlib(); | 28 | 34 | $pdf = new PDFlib(); | |
29 | 35 | |||
// set up some PDFlib options | 30 | 36 | // set up some PDFlib options | |
$pdf->set_option("errorpolicy=return"); | 31 | 37 | $pdf->set_option("errorpolicy=return"); | |
$pdf->set_option("stringformat=utf8"); | 32 | 38 | $pdf->set_option("stringformat=utf8"); | |
33 | 39 | |||
if ($pdf->begin_document($outfile, "") == 0) | 34 | 40 | if ($pdf->begin_document($outfile, "") == 0) | |
throw new Exception("Error: " . $pdf->get_errmsg()); | 35 | 41 | throw new Exception("Error: " . $pdf->get_errmsg()); | |
36 | 42 | |||
// set up the document metadata info | 37 | 43 | // set up the document metadata info | |
$pdf->set_info('Creator', 'IODP Science Support Office'); | 38 | 44 | $pdf->set_info('Creator', 'IODP Science Support Office'); | |
$pdf->set_info('Author', 'IODP Science Support Office'); | 39 | 45 | $pdf->set_info('Author', 'IODP Science Support Office'); | |
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | 40 | 46 | $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); | |
$pdf->set_info('Subject', 'IODP Proposals'); | 41 | 47 | $pdf->set_info('Subject', 'IODP Proposals'); | |
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | 42 | 48 | $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); | |
43 | 49 | |||
// START PAGE 1 | 44 | 50 | // START PAGE 1 | |
$pdf->begin_page_ext(612, 792, ''); | 45 | 51 | $pdf->begin_page_ext(612, 792, ''); | |
46 | 52 | |||
$textOpts = "fontname={Helvetica} embedding fontsize=20 " | 47 | 53 | $textOpts = "fontname={Helvetica} embedding fontsize=20 " | |
. "encoding=unicode "; | 48 | 54 | . "encoding=unicode "; | |
49 | 55 | |||
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, $textOpts); | 50 | 56 | $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, | |
57 | $textOpts . " underline=true"); | |||
$pdf->fit_textline("This is some text on the first page; ", 20, 720, | 51 | 58 | $pdf->fit_textline("This is some text on the first page; ", 20, 720, | |
$textOpts); | 52 | 59 | $textOpts); | |
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | 53 | 60 | $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); | |
54 | 61 | |||
// finish this page | 55 | 62 | // END PAGE 1 | |
$pdf->end_page_ext(''); | 56 | 63 | $pdf->end_page_ext(''); | |
57 | 64 | |||
// START PAGE 2 | 58 | 65 | // START PAGE 2 | |
//$pdf->begin_page_ext(612, 792, ''); | 59 | 66 | //$pdf->begin_page_ext(612, 792, ''); | |
//$pdf->end_page_ext(''); | 60 | 67 | $ssfPDF = $pdf->open_pdi_document(__DIR__ . "/site_summary_figure.pdf", ''); | |
68 | if ($ssfPDF == 0) | |||
69 | throw new Exception("Error: " . $p->get_errmsg()); | |||
70 | ||||
71 | $ssfPage = $pdf->open_pdi_page($ssfPDF, 1, ''); | |||
72 | $ssfWidth = $pdf->pcos_get_number($ssfPDF, "pages[0]/width"); | |||
73 | $ssfHeight = $pdf->pcos_get_number($ssfPDF, "pages[0]/height"); | |||
74 | ||||
75 | $pdf->begin_page_ext($ssfWidth, $ssfHeight, ''); | |||
76 | ||||
77 | $pdf->fit_pdi_page($ssfPage, 0, 0, ''); | |||
78 | $pdf->close_pdi_page($ssfPage); | |||
79 | $pdf->close_pdi_document($ssfPDF); | |||
80 | // END PAGE 2 | |||
81 | $pdf->end_page_ext(''); | |||
61 | 82 | |||
// close the document | 62 | 83 | // close the document | |
$pdf->end_document(''); | 63 | 84 | $pdf->end_document(''); | |
64 | 85 | |||
} | 65 | 86 | } | |
66 | 87 | |||
catch (PDFlibException $e) { | 67 | 88 | catch (PDFlibException $e) { | |
die("PDFlib exception occurred in sample:\n" . | 68 | 89 | die("PDFlib exception occurred in sample:\n" . | |
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . | 69 | 90 | "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . | |
$e->get_errmsg() . "\n"); | 70 | 91 | $e->get_errmsg() . "\n"); | |
} | 71 | 92 | } | |
72 | 93 | |||
catch (Exception $e) { | 73 | 94 | catch (Exception $e) { | |
die($e); | 74 | 95 | die($e); | |
} | 75 | 96 | } | |
76 | 97 | |||
$p = 0; | 77 | 98 | $p = 0; | |
78 | 99 | |||
/* | 79 | 100 | /* | |
// write out the contents of the first page | 80 | 101 | // write out the contents of the first page | |
$pdf->AddPage(); | 81 | 102 | $pdf->AddPage(); | |
$topLink = $pdf->AddLink(); | 82 | 103 | $topLink = $pdf->AddLink(); | |
$pdf->SetLink($topLink); | 83 | 104 | $pdf->SetLink($topLink); | |
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); | 84 | 105 | //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); | |
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); | 85 | 106 | $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); | |
//$pdf->SetFont('DejaVu', '', 20); | 86 | 107 | //$pdf->SetFont('DejaVu', '', 20); | |
$pdf->SetFont('dejavusanscondensed', '', 20); | 87 | 108 | $pdf->SetFont('dejavusanscondensed', '', 20); | |
$pdf->SetFont('', 'U'); | 88 | 109 | $pdf->SetFont('', 'U'); | |
$ssfLink = $pdf->AddLink(); | 89 | 110 | $ssfLink = $pdf->AddLink(); | |
$pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); | 90 | 111 | $pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); | |
$pdf->SetFont(''); | 91 | 112 | $pdf->SetFont(''); | |
$pdf->Ln(); | 92 | 113 | $pdf->Ln(); | |
$pdf->Write(10, "This is some text on the first page; "); | 93 | 114 | $pdf->Write(10, "This is some text on the first page; "); | |
$pdf->Ln(); | 94 | 115 | $pdf->Ln(); | |
$pdf->Write(10, "Привет! Этот немного текста."); | 95 | 116 | $pdf->Write(10, "Привет! Этот немного текста."); | |
96 | 117 | |||
// load up the Site Summary Figure to go on page #2 | 97 | 118 | // load up the Site Summary Figure to go on page #2 | |
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); | 98 | 119 | $ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); | |
//print "Page count of site summary figure form is $ssfPageCount\n"; | 99 | 120 | //print "Page count of site summary figure form is $ssfPageCount\n"; | |
100 | 121 | |||
// import the SSF page | 101 | 122 | // import the SSF page | |
$ssfTemplate= $pdf->importPage(1); | 102 | 123 | $ssfTemplate= $pdf->importPage(1); |