\"), " . "a system environment variable or (for Windows only) a registry " . "key. " . "See the source code for a detailed description. " . "See also chapter 0 in the PDFlib Tutorial for detailed " . "documentation about the licensing mechanism."; try { $p = new PDFlib(); /* --- First method: --- * * --- Apply the license key at runtime --- */ /* * Provide the "license" option with your license key. This must * be done immediately after having instantiated the PDFlib object * with "new pdflib()" In the following function call replace "0" * with your license key number. */ $p->set_option("license=0"); /* On Windows you can also enter the license key in the following * registry key: HKEY_LOCAL_MACHINE\SOFTWARE\PDFlib\PDFlib\9.0.0 * with a version of 9.0.0 for example */ /* (If you are working with the Windows COM .NET installer * you can enter a license key when you install the PDFlib product.) */ /* Using PDFlib+PDI functions if only the PDFlib license key has been * installed: * If you installed a valid PDFlib license key the PDI functionality * will no longer be available for testing. When a license key for a * product has already been installed, you can replace it with the * dummy license string "0" (zero) to enable functionality of a higher * product class for evaluation with: * * $p->set_option("license=0"); * * This will enable the previously disabled functions, and re-activate * the demo stamp across all pages. * This also applies to PDFlib+PDI and PPS. */ /* --- Alternative second method: --- * * --- Supply the license key in a license file --- */ /* Enter the license key in a text file according to the following * format (use the license file template "licensekeys.txt" which is * contained in all PDFlib distributions): PDFlib license file 1.0 # Licensing information for PDFlib GmbH products PDFlib * "PDFlib" indicates PDFlib, PDFlib+PDI, and PPS, respectively. * is the PDFlib version number, e.g. 9.0.0, and * is your license key. The license file may contain * license keys for multiple PDFlib GmbH products on separate lines. */ /* After the license key has been manually added to the license * file, either place the file "licensekeys.txt" in one of the * default locations that PDFlib searches (see section "Default * file search paths" in the PDFlib Tutorial), or inform PDFlib * about the license file in one of the following ways: $p->set_option("licensefile=path/to/licensekeys.txt"); * Alternatively, set the environment variable PDFLIBLICENSEFILE to * point to your license file. On Windows open the system control panel * and choose System, Advanced, Environment Variables, System variables. * On Unix apply a command similar to the following: export PDFLIBLICENSEFILE=/path/to/licensekeys.txt */ /* On Windows you can also enter the name of the license file in the * following registry key: HKLM\Software\PDFlib\PDFLIBLICENSEFILE */ /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); /* Start the first document. By default, a demo stamp will be generated * on all pages if no valid license key has been found. */ if ($p->begin_document("", "") == 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=a4.width height=a4.height"); $optlist = "fontname=Helvetica-Bold fontsize=16 encoding=unicode " . "fillcolor={gray 0} leading=140%"; $tf = $p->add_textflow(0, $text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); /* * Create a second PDFlib object for the demonstration of the * "avoiddemostamp" option. */ $tf = $p->add_textflow($tf, "\n\nTesting \"avoiddemostamp\" option:", $optlist); $p2 = new PDFlib(); try { /* By default a demo stamp will be created on all pages when no valid * license key has been found. However, we can force an exception in * those cases. This is recommended to be immediately informed about * problems with missing or invalid license keys which will result in * the unwanted demo stamp. Before beginning a new document, we set the * "avoiddemostamp" option to "true". An exception will be thrown when * no valid license key has been found. */ $p2->set_option("avoiddemostamp=true"); /* Start a new document */ $p2->begin_document("", ""); $p2->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $p2->end_page_ext(""); $p2->end_document(""); } catch (PDFlibException $e) { $text = "\n\nPDFlib exception occurred:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"; $tf = $p->add_textflow($tf, $text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); if ($e->get_errnum() == 1994) { $text = "\nThis behaviour is expected since we did not\n" . "supply a valid license key and set the\n" . "\"avoiddemostamp\" option to \"true\"."; $tf = $p->add_textflow($tf, $text, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); } } catch (Exception $e) { die($e->getMessage()); } $p2 = 0; $p->fit_textflow($tf, 50, 200, 400, 600, "fitmethod=auto"); $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=repeated_contents.pdf"); print $buf; } catch (PDFlibException $e){ print("PDFlib exception occurred:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); } catch (Exception $e) { print($e->getMessage() . "\n"); } $p = 0; ?>