pdflib_demo 3.42 KB
#!/usr/bin/env php
<?php
/**
* FILENAME:
* pdflib_demo
*
* DESCRIPTION:
* Demonstration of the pdflib PHP Library for generating PDF files
*
*/
/**
Links:
- https://www.pdflib.com/developer/technical-documentation/manuals/
- https://www.pdflib.com/pdflib-cookbook/browse-all-topics/
*/
// set a default timezone
date_default_timezone_set("America/Los_Angeles");
//require_once('tcpdf_include.php');
$outfile = __DIR__ . '/output.pdf';
// wrap PDFlib usage in a try{} block
try {
$pdf = new PDFlib();
// set up some PDFlib options
$pdf->set_option("errorpolicy=return");
$pdf->set_option("stringformat=utf8");
if ($pdf->begin_document($outfile, "") == 0)
throw new Exception("Error: " . $pdf->get_errmsg());
// set up the document metadata info
$pdf->set_info('Creator', 'IODP Science Support Office');
$pdf->set_info('Author', 'IODP Science Support Office');
$pdf->set_info('Title', 'Demo of TCPDF for generating IODP Proposals');
$pdf->set_info('Subject', 'IODP Proposals');
$pdf->set_info('Keywords', 'IODP proposal ocean drilling core expedition');
// START PAGE 1
$pdf->begin_page_ext(612, 792, '');
$textOpts = "fontname={Helvetica} embedding fontsize=20 "
. "encoding=unicode ";
$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,
$textOpts);
$pdf->fit_textline("Привет! Этот немного текста.", 20, 690, $textOpts);
// finish this page
$pdf->end_page_ext('');
// START PAGE 2
//$pdf->begin_page_ext(612, 792, '');
//$pdf->end_page_ext('');
// close the document
$pdf->end_document('');
}
catch (PDFlibException $e) {
die("PDFlib exception occurred in sample:\n" .
"[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
$e->get_errmsg() . "\n");
}
catch (Exception $e) {
die($e);
}
$p = 0;
/*
// write out the contents of the first page
$pdf->AddPage();
$topLink = $pdf->AddLink();
$pdf->SetLink($topLink);
//$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->AddFont('dejavusanscondensed','','dejavusanscondensed.php',true);
//$pdf->SetFont('DejaVu', '', 20);
$pdf->SetFont('dejavusanscondensed', '', 20);
$pdf->SetFont('', 'U');
$ssfLink = $pdf->AddLink();
$pdf->Write(10, "Jump to SSF for SHACK-10A", $ssfLink);
$pdf->SetFont('');
$pdf->Ln();
$pdf->Write(10, "This is some text on the first page; ");
$pdf->Ln();
$pdf->Write(10, "Привет! Этот немного текста.");
// load up the Site Summary Figure to go on page #2
$ssfPageCount = $pdf->setSourceFile(__DIR__ . '/site_summary_figure.pdf');
//print "Page count of site summary figure form is $ssfPageCount\n";
// import the SSF page
$ssfTemplate= $pdf->importPage(1);
//print "Page size of site summary figure PDF is: ";
//$ssfSize = $pdf->getTemplateSize($ssfTemplate);
//print "{$ssfSize['w']}mm x {$ssfSize['h']}mm\n";
// add the SSF file to the 2nd page
$pdf->AddPage();
$pdf->SetLink($ssfLink);
$pdf->useTemplate($ssfTemplate);
$pdf->SetFont('Helvetica');
$pdf->SetXY(5,5);
$pdf->SetFont('', 'U');
$pdf->Write(8, "Top", $topLink);
$pdf->SetFont('');
$pdf->SetXY(40, 5);
$pdf->Write(8, " SSF: P771/SHACK-10A");
// destination, F = "local file"; filename; isUTF8 (boolean)
//$pdf->Output('F', 'output.pdf', TRUE);
$pdf->Output(__DIR__ . '/output.pdf', 'F');
*/
// vim: expandtab filetype=php shiftwidth=3 tabstop=3