From 5b784109da223e537ed2f71f9280f5ec09386639 Mon Sep 17 00:00:00 2001 From: Brian Manning Date: Mon, 25 Apr 2016 18:20:44 -0700 Subject: [PATCH] pdflib_demo: basic text drawing and writing of the output PDF works --- pdflib_demo | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/pdflib_demo b/pdflib_demo index 4537340..1719e26 100755 --- a/pdflib_demo +++ b/pdflib_demo @@ -15,23 +15,63 @@ - https://www.pdflib.com/developer/technical-documentation/manuals/ - https://www.pdflib.com/pdflib-cookbook/browse-all-topics/ - PDFlib was loaded via a Homebrew package for working with this demo */ -$loader = require __DIR__ . '/vendor/autoload.php'; -$loader->register(); - // set a default timezone date_default_timezone_set("America/Los_Angeles"); //require_once('tcpdf_include.php'); -//$pdf = new TCPDF('p', 'mm', 'Letter', TRUE, 'UTF-8'); -class_exists('TCPDF', true); -$pdf = new FPDI('p', 'mm', 'Letter', TRUE, 'UTF-8'); -// disable headers and footers on all pages -$pdf->setPrintHeader(FALSE); -$pdf->setPrintFooter(FALSE); +$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'); + + $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(''); + + // 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(); @@ -74,5 +114,6 @@ $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 -- 1.9.1