create_pvf("/pvf/font/bitmap" . $i, $data[$i], ""); } } /* Create the "T3font" widths-only font in pass 1 */ $optlist = ""; if ($pass == 1) $optlist = "widthsonly=true"; $p->begin_font("T3Font", 1/16.0, 0, 0, 1/16.0, 0, -3/16.0, $optlist); /* The .notdef (fallback) glyph should be contained in all Type 3 * fonts to avoid problems with some PDF viewers. It is usually empty. * Therefore we don't have to distinguish between pass 1 and pass 2. */ $p->begin_glyph_ext(0x0000, "width=8"); $p->end_glyph(); /* Define the glyph "a" */ $p->begin_glyph_ext(0x0061, "width=8 boundingbox={0 0 8 16}"); /* In pass 2, 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). */ $optlist = "inline bpc=1 components=1 height=16 width=8 mask invert"; if ($pass == 2) { $image = $p->load_image("raw", "/pvf/font/bitmap0", $optlist); if ($image == 0 && $p->get_errnum() > 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}"); if ($pass == 2) { $image = $p->load_image("raw", "/pvf/font/bitmap1", $optlist); if ($image == 0 && $p->get_errnum() > 0) throw new Exception("Error: " . $p->get_errmsg()); } $p->end_glyph(); /* ...define all glyph descriptions... */ $p->end_font(); } try { $p = new pdflib(); $p->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); /* Pass 1: Create the widths-only font to make it known to PDFlib */ define_font($p, 1); /* Create some text on the page with glyphs from the font. Loading the * font with the "subsetting" option will include only those glyphs in * the font which are actually used in the document. */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $font = $p->load_font("T3Font", "unicode", "subsetting"); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_textline("a", 50, 700, "font=" . $font . " fontsize=36"); $p->end_page_ext(""); /* Pass 2: Supply glyph descriptions for the font */ define_font($p, 2); $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_subsetting.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e->getMessage()); exit(1); } $p = 0; ?>