1<?php
2/*
3 * $Id: chartab.php 14574 2005-10-29 16:27:43Z bonefish $
4 * PDFlib client: chartab example in PHP
5 */
6
7/* change these as required */
8$fontname = "LuciduxSans-Oblique";
9
10/* This is where font/image/PDF input files live. Adjust as necessary. */
11$searchpath = "../data";
12
13/* list of encodings to use */
14$encodings = array( "iso8859-1", "iso8859-2", "iso8859-15" );
15
16/* whether or not to embed the font */
17$embed = 1;
18
19define("FONTSIZE", 	16);
20define("TOP",		700);
21define("LEFT", 		50);
22define("YINCR", 	2*FONTSIZE);
23define("XINCR",		2*FONTSIZE);
24
25/* create a new PDFlib object */
26$p = PDF_new();
27
28
29/* open new PDF file */
30if (PDF_open_file($p, "") == 0) {
31    die("Error: " . PDF_get_errmsg($p));
32}
33
34PDF_set_parameter($p, "openaction", "fitpage");
35PDF_set_parameter($p, "fontwarning", "true");
36PDF_set_parameter($p, "SearchPath", $searchpath);
37
38/* This line is required to avoid problems on Japanese systems */
39PDF_set_parameter($p, "hypertextencoding", "winansi");
40
41PDF_set_info($p, "Creator", "chartab.php");
42PDF_set_info($p, "Author", "Thomas Merz");
43PDF_set_info($p, "Title", "Character table (PHP)");
44
45/* loop over all encodings */
46for ($page = 0; $page < count($encodings); $page++)
47{
48    PDF_begin_page($p, 595, 842);  /* start a new page */
49
50    /* print the heading and generate the bookmark */
51    $font = PDF_load_font($p, "Helvetica", "winansi", "");
52    PDF_setfont($p, $font, FONTSIZE);
53    $buf = sprintf("%s (%s) %sembedded",
54	$fontname, $encodings[$page], $embed ? "" : "not ");
55
56    PDF_show_xy($p, $buf, LEFT - XINCR, TOP + 3 * YINCR);
57    PDF_add_bookmark($p, $buf, 0, 0);
58
59    /* print the row and column captions */
60    PDF_setfont($p, $font, 2 * FONTSIZE/3);
61
62    for ($row = 0; $row < 16; $row++)
63    {
64	$buf = sprintf("x%X", $row);
65	PDF_show_xy($p, $buf, LEFT + $row*XINCR, TOP + YINCR);
66
67	$buf = sprintf("%Xx", $row);
68	PDF_show_xy($p, $buf, LEFT - XINCR, TOP - $row * YINCR);
69    }
70
71    /* print the character table */
72    $font = PDF_load_font($p, $fontname, $encodings[$page],
73	$embed ? "embedding": "");
74    PDF_setfont($p, $font, FONTSIZE);
75
76    $y = TOP;
77    $x = LEFT;
78
79    for ($row = 0; $row < 16; $row++)
80    {
81	for ($col = 0; $col < 16; $col++) {
82	    $buf = sprintf("%c", 16*$row + $col);
83	    PDF_show_xy($p, $buf, $x, $y);
84	    $x += XINCR;
85	}
86	$x = LEFT;
87	$y -= YINCR;
88    }
89
90    PDF_end_page($p);			/* close page */
91}
92
93
94PDF_close($p);				/* close PDF document	*/
95
96$buf = PDF_get_buffer($p);
97$len = strlen($buf);
98
99header("Content-type: application/pdf");
100header("Content-Length: $len");
101header("Content-Disposition: inline; filename=hello.pdf");
102print $buf;
103
104PDF_delete($p);				/* delete the PDFlib object */
105?>
106