set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return "); $p->set_option("stringformat=utf8"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title ); /* From the data defining three glyphs, create three PVFs * "/pvf/font/bitmap0" ... "/pvf/font/bitmap2" */ for ($i=0; $i < count($data); $i++) { $p->create_pvf("/pvf/font/bitmap" . $i, $data[$i], ""); } /* Create the "BitmapFont" font */ $p->begin_font("BitmapFont", 1/16.0, 0, 0, 1/16.0, 0, -3/16.0, ""); /* Start the glyph definition for "a" */ $p->begin_glyph_ext(0x0061, "width=8 boundingbox={0 0 8 16}"); /* Load the bitmap data for the glyph from the PVF. * The "inline" option is provided so that load_image() will internally * perform the equivalent of fit_image(image, 0, 0, "") and * close_image(image). */ $image = $p->load_image("raw", "/pvf/font/bitmap0", $optlist); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->end_glyph(); /* Define the glyph "b" */ $p->begin_glyph_ext(0x0062, "width=8 boundingbox={0 0 8 16}"); $image = $p->load_image("raw", "/pvf/font/bitmap1", $optlist); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->end_glyph(); /* Define the glyph "c" */ $p->begin_glyph_ext(0x0063, "width=8 boundingbox={0 0 8 16}"); $image = $p->load_image("raw", "/pvf/font/bitmap2", $optlist); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->end_glyph(); /* The .notdef (fallback) glyph should be contained in all Type 3 * fonts to avoid problems with some PDF viewers. It is usually * empty. */ $p->begin_glyph_ext(0x0000, "width=8 boundingbox={0 0 8 16}"); $p->end_glyph(); $p->end_font(); $p->begin_page_ext(0, 0, "width=200 height=300"); /* Load the new "BitmapFont" font */ $bitmapfont = $p->load_font("BitmapFont", "unicode", "embedding"); if ($bitmapfont == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Output the characters "a", "b", and "c" */ $p->fit_textline("a", 70, 200, "font=" . $bitmapfont . " fontsize=36"); $p->fit_textline("b", 70, 150, "font=" . $bitmapfont . " fontsize=36"); $p->fit_textline("c", 70, 100, "font=" . $bitmapfont . " fontsize=36"); $p->end_page_ext(""); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=type3_bitmaptext.pdf"); print $buf; } catch (PDFlibException $e) { die("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); } catch (Exception $e) { die($e->getMessage()); } $p = 0; ?>