set_option("searchpath={" . SEARCH_PATH . "}"); /* * Load a font */ if ($keepfont) { /* * keepfont=true is default here, so it does not need to be * specified explicitly. */ $font = $p->load_font(FONTNAME, "unicode", "keepfont=true"); if ($font == 0) throw new Exception("Error: " . $p->get_apiname() . ": " . $p->get_errmsg()); } for ($i = 0; $i < N_DOCS; $i += 1) { /* * Create a simple document that makes use of the font. The * document is generated in memory and immediately discarded. */ if ($p->begin_document("", "") == 0) throw new Exception("Error: " . $p->get_apiname() . ": " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", "Dummy test document"); $p->begin_page_ext(WIDTH, HEIGHT, ""); if (!$keepfont) { /* * keepfont=false is default here. */ $font = $p->load_font(FONTNAME, "unicode", "keepfont=false"); if ($font == 0) throw new Exception("Error: " . $p->get_apiname() . ": " . $p->get_errmsg()); } $p->fit_textline("Hello world!", 50, 700, "font=" . $font . " fontsize=24"); $p->end_page_ext(""); $p->end_document(""); } } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); } catch (Exception $e) { echo($e->getMessage()); } $p=0; } $outfile = ""; $title = "Retain Fonts"; /* * Time creation of test documents with and without retaining of font. */ $start_date1 = microtime(true); make_test_docs(false); $time_diff1 = sprintf("%.2f", microtime(true) - $start_date1); $start_date2 = microtime(true); make_test_docs(true); $time_diff2 = sprintf("%.2f", microtime(true) - $start_date2); try { $p = new PDFlib(); $p->set_option("searchpath={" . SEARCH_PATH . "}"); /* 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_apiname() . ": " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title ); $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $tf = 0; $tf = $p->add_textflow($tf, "Performance benefit of retaining a font across documents:\n\n", "fontname=NotoSerif-Regular encoding=unicode fontsize=18"); $tf = $p->add_textflow($tf, "Time spent for creating " . N_DOCS . " documents without retaining font:\n", "fontsize=16"); $tf = $p->add_textflow($tf, $time_diff1 . " seconds\n\n", ""); $tf = $p->add_textflow($tf, "Time spent for creating " . N_DOCS . " documents while retaining font:\n", ""); $tf = $p->add_textflow($tf, $time_diff2 . " seconds\n\n", ""); $tf = $p->add_textflow($tf, "Note: Actual results will vary depending on various factors,\n" . "including font, complexity of the document and platform.", ""); $p->fit_textflow($tf, 50, 50, 545, 716, ""); $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=opentype_features_for_cjk.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; ?>