1<?php 2/* $Id: quickreference.php,v 1.6.2.1 2008/04/06 17:55:03 rp Exp $ 3 * 4 * PDFlib+PDI client: mini imposition demo 5 */ 6 7$infile = "reference.pdf"; 8/* This is where font/image/PDF input files live. Adjust as necessary. */ 9$searchpath = "../data"; 10$maxrow = 2; 11$maxcol = 2; 12$width = 500.0; 13$height = 770.0; 14$endpage = 0; 15 16try { 17 $p = new PDFlib(); 18 19 # This means we must check return values of load_font() etc. 20 $p->set_parameter("errorpolicy", "return"); 21 22 $p->set_parameter("SearchPath", $searchpath); 23 24 /* open new PDF file; insert a file name to create the PDF on disk */ 25 if ($p->begin_document("", "") == 0) { 26 die("Error: " . $p->get_errmsg()); 27 } 28 29 /* This line is required to avoid problems on Japanese systems */ 30 $p->set_parameter("hypertextencoding", "winansi"); 31 32 $p->set_info("Creator", "quickreference.php"); 33 $p->set_info("Author", "Thomas Merz"); 34 $p->set_info("Title", "mini imposition demo (php)"); 35 36 $manual = $p->open_pdi($infile, "", 0); 37 if (!$manual) { 38 die("Error: " . $p->get_errmsg()); 39 } 40 41 $row = 0; 42 $col = 0; 43 44 $p->set_parameter("topdown", "true"); 45 46 $endpage = $p->pcos_get_number($manual, "length:pages"); 47 48 for ($pageno = 1; $pageno <= $endpage; $pageno++) { 49 if ($row == 0 && $col == 0) { 50 $p->begin_page_ext($width, $height, ""); 51 $font = $p->load_font("Helvetica-Bold", "winansi", ""); 52 if ($font == 0) { 53 die("Error: " . $p->get_errmsg()); 54 } 55 $p->setfont($font, 18); 56 $p->set_text_pos(24, 24); 57 $p->show("PDFlib Quick Reference"); 58 } 59 60 $page = $p->open_pdi_page($manual, $pageno, ""); 61 62 if (!$page) { 63 die("Error: " . $p->get_errmsg()); 64 } 65 66 $optlist = sprintf("scale %f", 1/$maxrow); 67 68 $p->fit_pdi_page($page, 69 $width/$maxcol*$col, ($row + 1) * $height/$maxrow, $optlist); 70 $p->close_pdi_page($page); 71 72 $col++; 73 if ($col == $maxcol) { 74 $col = 0; 75 $row++; 76 } 77 if ($row == $maxrow) { 78 $row = 0; 79 $p->end_page_ext(""); 80 } 81 } 82 83 /* finish the last partial page */ 84 if ($row != 0 || $col != 0) { 85 $p->end_page_ext(""); 86 } 87 88 $p->end_document(""); 89 $p->close_pdi($manual); 90 91 $buf = $p->get_buffer(); 92 $len = strlen($buf); 93 94 header("Content-type: application/pdf"); 95 header("Content-Length: $len"); 96 header("Content-Disposition: inline; filename=quickreference_php.pdf"); 97 print $buf; 98 99} 100catch (PDFlibException $e) { 101 die("PDFlib exception occurred in quickreference sample:\n" . 102 "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . 103 $e->get_errmsg() . "\n"); 104} 105catch (Exception $e) { 106 die($e); 107} 108 109$p = 0; 110?> 111