set_option("errorpolicy=return"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* Start page */ $p->begin_page_ext(0, 0, "width=300 height=300"); /* The convenient way: load a host font on Windows or Mac which is * already installed in the system. In this case no prerequisites * are required provided that you know the exact (case-sensitive) * name of the font (see the PDFlib Tutorial for information about * how to retrieve the exact name of a host font). For example, if * you installed the font "Verdana" in the system you can load it * just as follows. */ /* The following will only work on Mac or Windows, provided the * font Verdana is installed in the system. $font = $p->load_font("Verdana", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->setfont($font, 10); $p->fit_textline("Font file is installed in the system", $x, $y, ""); $fontname = $p->get_string($p->info_font(font, "fontname", "api"), ""); $p->fit_textline("Font name used in PDFlib: " . $fontname, $x, $y-=20, ""); */ /* If you do not want to use a host font the location of the font files * must be provided. Use the "SearchPath" resource category to define * the folder for your fonts to be searched in. Add similar * "Searchpath" commands to define further folders if necessary. PDFlib * will first search the font in all folders defined with "Searchpath". */ $p->set_option("searchpath={" . $searchpath . "}"); /* If you know the font name and the font file name (excluding the * file name extension such as ".ttf", ".otf", ".pfb" etc.) is equal * to the font name, you can simply load the font. */ /* Alternatively, you can supply an absolute path name such as * * $p->set_option(FontOutline=NotoSerif-Regular=/usr/fonts/NotoS-R.ttf"); * * In this case the font is loaded from the location defined above * without the searchpath being applied. */ /* Now you can load the font using the name "NotoSerif-Regular". */ $font = $p->load_font("NotoSerif-Regular", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->setfont($font, 10); $p->fit_textline("Font file name: NotoSerif-Regular.ttf", $x, $y-=40, ""); $fontname = $p->get_string($p->info_font($font, "fontname", "api"), ""); $p->fit_textline("Font name used in PDFlib: " . $fontname, $x, $y-=20, ""); /* Finish page */ $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=font_configuration.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo("PHP exception occurred: " . $e->getMessage() . "\n"); exit(1); } $p = 0; ?>