1<?php
2/* $Id: businesscard.php 14574 2005-10-29 16:27:43Z bonefish $
3 * PDFlib client: businesscard example in PHP
4 *
5 */
6
7
8$infile = "boilerplate.pdf";
9
10/* This is where font/image/PDF input files live. Adjust as necessary.
11 *
12 * Note that this directory must also contain the LuciduxSans font outline
13 * and metrics files.
14 */
15$searchpath = "../data";
16
17$data = array(  "name"				=> "Victor Kraxi",
18		"business.title"		=> "Chief Paper Officer",
19		"business.address.line1" 	=> "17, Aviation Road",
20		"business.address.city"		=> "Paperfield",
21		"business.telephone.voice"	=> "phone +1 234 567-89",
22		"business.telephone.fax"	=> "fax +1 234 567-98",
23		"business.email"		=> "victor@kraxi.com",
24		"business.homepage"		=> "www.kraxi.com"
25	);
26
27$p = PDF_new();
28
29/*  open new PDF file; insert a file name to create the PDF on disk */
30if (PDF_open_file($p, "") == 0) {
31    die("Error: " . PDF_get_errmsg($p));
32}
33
34PDF_set_parameter($p, "SearchPath", $searchpath);
35
36/* This line is required to avoid problems on Japanese systems */
37PDF_set_parameter($p, "hypertextencoding", "winansi");
38
39PDF_set_info($p, "Creator", "businesscard.php");
40PDF_set_info($p, "Author", "Thomas Merz");
41PDF_set_info($p, "Title", "PDFlib block processing sample (PHP)");
42
43$blockcontainer = PDF_open_pdi($p, $infile, "", 0);
44if ($blockcontainer == 0){
45    die ("Error: " . PDF_get_errmsg($p));
46}
47
48$page = PDF_open_pdi_page($p, $blockcontainer, 1, "");
49if ($page == 0){
50    die ("Error: " . PDF_get_errmsg($p));
51}
52
53PDF_begin_page($p, 20, 20);		/* dummy page size */
54
55/* This will adjust the page size to the block container's size. */
56PDF_fit_pdi_page($p, $page, 0, 0, "adjustpage");
57
58/* Fill all text blocks with dynamic data */
59foreach ($data as $key => $value){
60    if (PDF_fill_textblock($p, $page, $key, $value,
61        "embedding encoding=winansi") == 0) {
62	printf("Warning: %s\n ", PDF_get_errmsg($p));
63    }
64}
65
66PDF_end_page($p);			/* close page */
67PDF_close_pdi_page($p, $page);
68
69PDF_close($p);				/* close PDF document */
70PDF_close_pdi($p, $blockcontainer);
71
72$buf = PDF_get_buffer($p);
73$len = strlen($buf);
74
75header("Content-type: application/pdf");
76header("Content-Length: $len");
77header("Content-Disposition: inline; filename=businesscard.pdf");
78print $buf;
79
80PDF_delete($p);				/* delete the PDFlib object */
81?>
82