usecase = $usecase; $this->fontname = $fontname; $this->encoding = $encoding; $this->fallbackoptions = $fallbackoptions; $this->text = $text; } public $usecase; public $fontname; public $encoding; public $fallbackoptions; public $text; } $testcases = array( /* Add Euro glyph to an encoding which doesn't support it */ new testcase( "Extend 8-bit encoding", "Helvetica", "iso8859-1", "{fontname=Helvetica encoding=unicode forcechars=euro}", /* * Reference Euro glyph by name (since it is missing from * the encoding) */ "123€"), new testcase( "Use Euro glyph from another font", "Courier", "unicode", "{fontname=Helvetica encoding=unicode forcechars=euro textrise=-5%}", "123€"), new testcase( "Add enlarged pictogram", "NotoSerif-Regular", "unicode", /* U+261E = WHITE RIGHT POINTING INDEX */ "{fontname=ZapfDingbats encoding=unicode forcechars=U+261E fontsize=150% " . "textrise=-15%}", "hand symbol: \u{261E}"), new testcase( "Add enlarged symbol glyph", "NotoSerif-Regular", "unicode", "{fontname=Symbol encoding=unicode forcechars=U+2663 fontsize=125%}", "club symbol: \u{2663}"), /* * Hebrew characters missing in the font will be pulled from Hebrew * font */ new testcase( "Add Hebrew characters to Latin font", "NotoSerif-Regular", "unicode", "{fontname=NotoSerifHebrew-Regular encoding=unicode}", "Hebrew: \u{05D0}"), /* Font with end-user defined character (EUDC) */ new testcase( "Gaiji with EUDC font", "KozMinProVI-Regular", "unicode", "{fontname=EUDC encoding=unicode forcechars=U+E000 fontsize=140% " . "textrise=-20%}", "Gaiji: \u{E000}"), new testcase( "Replace Latin characters in CJK font", "KozMinProVI-Regular", "unicode", "{fontname=Courier encoding=unicode forcechars={U+0020-U+007E}}", "Latin and \u{65E5}\u{672C}\u{8A9E}"), ); try { $p = new pdflib(); $p->set_option("searchpath={" . $searchpath . "}"); $p->set_option("charref=true"); $p->set_option("glyphcheck=replace"); $p->set_option("stringformat=utf8"); /* * This means that formatting and other errors will raise an * exception. This simplifies our sample code, but is not * recommended for production code. */ $p->set_option("errorpolicy=exception"); /* Set an output path according to the name of the topic */ if ($p->begin_document($outfile, "") == 0) { throw new Exception("Error: " . $p->get_errmsg()); } $p->set_info("Creator", "PDFlib starter sample"); $p->set_info("Title", "starter_fallback"); /* Start Page */ $p->begin_page_ext(0, 0, "width=a4.height height=a4.width"); $table = 0; /* Table header */ for ($i = 0; $i < count($headers); $i++) { $col = $i + 1; $optlist = "fittextline={fontname=NotoSerif-Bold encoding=unicode fontsize=10} " . "margin=4"; $table = $p->add_table_cell($table, $col, 1, $headers[$i], $optlist); } /* Create fallback samples, one use case per row */ for ($i = 0; $i < count($testcases); $i++) { $row = $i + 2; $testcase = $testcases[$i]; $col = 1; /* Column 1: description of the use case */ $optlist = "fittextline={fontname=NotoSerif-Regular encoding=unicode fontsize=10} " . "margin=4"; $table = $p->add_table_cell($table, $col++, $row, $testcase->usecase, $optlist); /* Column 2: reproduce option list literally */ $optlist = "fittextline={fontname=NotoSerif-Regular encoding=unicode fontsize=10} " . "margin=4"; $table = $p->add_table_cell($table, $col++, $row, $testcase->fallbackoptions, $optlist); /* Column 3: text with base font */ $optlist = "fittextline={fontname=" . $testcase->fontname . " encoding=" . $testcase->encoding . " fontsize=10 replacementchar=? } margin=4"; $table = $p->add_table_cell($table, $col++, $row, $testcase->text, $optlist); /* Column 4: text with base font and fallback fonts */ $optlist = "fittextline={fontname=" . $testcase->fontname . " encoding=" . $testcase->encoding . " fontsize=10 fallbackfonts={" . $testcase->fallbackoptions . "}} margin=4"; $table = $p->add_table_cell($table, $col++, $row, $testcase->text, $optlist); } /* Place the table */ $optlist = "header=1 fill={{area=rowodd " . "fillcolor={gray 0.9}}} stroke={{line=other}} "; $result = $p->fit_table($table, $llx, $lly, $urx, $ury, $optlist); if ($result == "_error") { throw new Exception("Couldn't place table: " . $p->get_errmsg()); } $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=hello.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in starter_fallback sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e); exit(1); } $p = 0; ?>