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); $font = $p->load_font("Helvetica", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* * While it is possible to specify the the expansion of escape * sequences with a global parameter, this can have unwanted * consequences because for example environment variables are * treated by PDFLib as "name strings", and on Windows the backslash * is used in pathnames (example: environment variable * "PDFLIBLICENSEFILE" for specifying the pathname of the PDFlib * license file). * * Therefore it is strongly recommended to always specify the * "escapesequence" option for each function where it is necessary, * and not to set it as a global option. */ /* Start page */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Set the font and font size */ $p->setfont($font, 18); /* Output some descriptive text, i.e. the header for a kind of * input/output table */ $p->fit_textline("Input", $x, $y, "underline underlinewidth=1"); $p->fit_textline("Output", $x+$xoff, $y, "underline underlinewidth=1"); /* * Output some text in octal notation using escape sequences. At the * PHP level we need an additional backslash to escape the * backslash itself. */ $testcases = array( // octal notation "\\160", // "p" // hexadecimal notation "\\xC3\\x84", // LATIN CAPITAL LETTER A WITH DIARESIS "\\xC3\\x96", // LATIN CAPITAL LETTER O WITH DIARESIS "\\xC3\\x9C" // LATIN CAPITAL LETTER U WITH DIARESIS ); for ($i = 0; $i < count($testcases); $i += 1) { $ypos = $y - (($i + 1) * $yoff); /* * Show the input text. As the default for the "escapesequence" * option is "false", the string will be shown as-is. */ $p->fit_textline($testcases[$i], $x, $ypos, ""); /* * Let PDFlib replace the escape sequence and show the resulting * text. */ $p->fit_textline($testcases[$i], $x + $xoff, $ypos, "escapesequence=true"); } /* 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=escape_sequences.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; ?>