Commit 8abb8dc7639c0f05c50a705f4cd205a853fcfe20

Authored by Brian Manning
1 parent 5b784109da

pdflib_demo: added 2nd page

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

#!/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 17
*/ 18 18 */
19 19
// set a default timezone 20 20 // set a default timezone
date_default_timezone_set("America/Los_Angeles"); 21 21 date_default_timezone_set("America/Los_Angeles");
22 22
//require_once('tcpdf_include.php'); 23 23 //require_once('tcpdf_include.php');
$outfile = __DIR__ . '/output.pdf'; 24 24 $outfile = __DIR__ . '/output.pdf';
25 25
// wrap PDFlib usage in a try{} block 26 26 // wrap PDFlib usage in a try{} block
try { 27 27 try {
$pdf = new PDFlib(); 28 28 $pdf = new PDFlib();
29 29
// set up some PDFlib options 30 30 // set up some PDFlib options
$pdf->set_option("errorpolicy=return"); 31 31 $pdf->set_option("errorpolicy=return");
$pdf->set_option("stringformat=utf8"); 32 32 $pdf->set_option("stringformat=utf8");
33 33
if ($pdf->begin_document($outfile, "") == 0) 34 34 if ($pdf->begin_document($outfile, "") == 0)
throw new Exception("Error: " . $pdf->get_errmsg()); 35 35 throw new Exception("Error: " . $pdf->get_errmsg());
36 36
// set up the document metadata info 37 37 // set up the document metadata info
$pdf->set_info('Creator', 'IODP Science Support Office'); 38 38 $pdf->set_info('Creator', 'IODP Science Support Office');
$pdf->set_info('Author', 'IODP Science Support Office'); 39 39 $pdf->set_info('Author', 'IODP Science Support Office');
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals'); 40 40 $pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals');
$pdf->set_info('Subject', 'IODP Proposals'); 41 41 $pdf->set_info('Subject', 'IODP Proposals');
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition'); 42 42 $pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition');
43 43
44 // START PAGE 1
$pdf->begin_page_ext(612, 792, ''); 44 45 $pdf->begin_page_ext(612, 792, '');
45 46
$textOpts = "fontname={Helvetica} embedding fontsize=20 " 46 47 $textOpts = "fontname={Helvetica} embedding fontsize=20 "
. "encoding=unicode "; 47 48 . "encoding=unicode ";
48 49
$pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, $textOpts); 49 50 $pdf->fit_textline("Jump to SSF for SHACK-10A", 20, 750, $textOpts);
$pdf->fit_textline("This is some text on the first page; ", 20, 720, 50 51 $pdf->fit_textline("This is some text on the first page; ", 20, 720,
$textOpts); 51 52 $textOpts);
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts); 52 53 $pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts);
53 54
// finish this page 54 55 // finish this page
$pdf->end_page_ext(''); 55 56 $pdf->end_page_ext('');
57
58 // START PAGE 2
59 //$pdf->begin_page_ext(612, 792, '');
60 //$pdf->end_page_ext('');
56 61
// close the document 57 62 // close the document
$pdf->end_document(''); 58 63 $pdf->end_document('');
59 64
} 60 65 }
61 66
catch (PDFlibException $e) { 62 67 catch (PDFlibException $e) {
die("PDFlib exception occurred in sample:\n" . 63 68 die("PDFlib exception occurred in sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . 64 69 "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n"); 65 70 $e->get_errmsg() . "\n");
} 66 71 }
67 72
catch (Exception $e) { 68 73 catch (Exception $e) {
die($e); 69 74 die($e);
} 70 75 }
71 76
$p = 0; 72 77 $p = 0;
73 78
/* 74 79 /*
// write out the contents of the first page 75 80 // write out the contents of the first page
$pdf->AddPage(); 76 81 $pdf->AddPage();
$topLink = $pdf->AddLink(); 77 82 $topLink = $pdf->AddLink();
$pdf->SetLink($topLink); 78 83 $pdf->SetLink($topLink);
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true); 79 84 //$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true); 80 85 $pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true);
//$pdf->SetFont('DejaVu', '', 20); 81 86 //$pdf->SetFont('DejaVu', '', 20);
$pdf->SetFont('dejavusanscondensed', '', 20); 82 87 $pdf->SetFont('dejavusanscondensed', '', 20);
$pdf->SetFont('', 'U'); 83 88 $pdf->SetFont('', 'U');
$ssfLink = $pdf->AddLink(); 84 89 $ssfLink = $pdf->AddLink();
$pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink); 85 90 $pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink);
$pdf->SetFont(''); 86 91 $pdf->SetFont('');
$pdf->Ln(); 87 92 $pdf->Ln();
$pdf->Write(10, "This is some text on the first page; "); 88 93 $pdf->Write(10, "This is some text on the first page; ");
$pdf->Ln(); 89 94 $pdf->Ln();
$pdf->Write(10, "Привет! Этот немного текста."); 90 95 $pdf->Write(10, "Привет! Этот немного текста.");
91 96
// load up the Site Summary Figure to go on page #2 92 97 // load up the Site Summary Figure to go on page #2
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf'); 93 98 $ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf');
//print "Page count of site summary figure form is $ssfPageCount\n"; 94 99 //print "Page count of site summary figure form is $ssfPageCount\n";
95 100