1<?php
2# $Id: quickreference.php 14574 2005-10-29 16:27:43Z bonefish $
3
4$infile    = "reference.pdf";
5/* This is where font/image/PDF input files live. Adjust as necessary. */
6$searchpath = "../data";
7$maxrow    = 2;
8$maxcol    = 2;
9$width     = 500.0;
10$height    = 770.0;
11$startpage = 1;
12$endpage   = 4;
13
14$p = PDF_new();					/* create a new PDFlib object */
15
16/*  open new PDF file; insert a file name to create the PDF on disk */
17if (PDF_open_file($p, "") == 0) {
18    die("Error: " . PDF_get_errmsg($p));
19}
20
21PDF_set_parameter($p, "SearchPath", $searchpath);
22
23/* This line is required to avoid problems on Japanese systems */
24PDF_set_parameter($p, "hypertextencoding", "winansi");
25
26PDF_set_info($p, "Creator", "quickreference.php");
27PDF_set_info($p, "Author", "Thomas Merz");
28PDF_set_info($p, "Title", "mini imposition demo (php)");
29
30$manual = PDF_open_pdi($p, $infile, "", 0);
31if (!$manual) {
32    die("Error: " . PDF_get_errmsg($p));
33}
34
35$row = 0;
36$col = 0;
37
38PDF_set_parameter($p, "topdown", "true");
39
40for ($pageno = $startpage; $pageno <= $endpage; $pageno++) {
41    if ($row == 0 && $col == 0) {
42	PDF_begin_page($p, $width, $height);
43	$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
44	PDF_setfont($p, $font, 18);
45	PDF_set_text_pos($p, 24, 24);
46	PDF_show($p, "PDFlib Quick Reference");
47    }
48
49    $page = PDF_open_pdi_page($p, $manual, $pageno, "");
50
51    if (!$page) {
52	die("Error: " . PDF_get_errmsg($p));
53    }
54
55    $optlist = sprintf("scale %f", 1/$maxrow);
56
57    PDF_fit_pdi_page($p, $page,
58	$width/$maxcol*$col, ($row + 1) * $height/$maxrow, $optlist);
59    PDF_close_pdi_page($p, $page);
60
61    $col++;
62    if ($col == $maxcol) {
63	$col = 0;
64	$row++;
65    }
66    if ($row == $maxrow) {
67	$row = 0;
68	PDF_end_page($p);
69    }
70}
71
72/* finish the last partial page */
73if ($row != 0 || $col != 0) {
74    PDF_end_page($p);
75}
76
77PDF_close($p);
78PDF_close_pdi($p, $manual);
79
80$buf = PDF_get_buffer($p);
81$len = strlen($buf);
82
83header("Content-type: application/pdf");
84header("Content-Length: $len");
85header("Content-Disposition: inline; filename=quickreference_php.pdf");
86print $buf;
87
88PDF_delete($p);
89?>
90