set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); /* 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 Cookbook"); $p->set_info("Title", $title ); /* Page 1 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Fit the text line as outlines like a stamp in the specified box. The * stamp will be placed diagonally from the upper left to the lower * right (stamp=ul2lr). */ $p->fit_textline("The Famous Rocket Looper", $llx, $lly, "fontname=NotoSerif-Bold " . "strokecolor={rgb 1 0 0} textrendering=1 boxsize={500 750} " . "strokecolor={rgb 0.5 0 1} stamp=ul2lr"); /* Place the Textflow on top of the stamp */ $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 100, 100, 400, 700, ""); if ($result != "_stop") { /* Check for errors or more text to be placed */ } $p->end_page_ext(""); /* Page 2 */ $p->begin_page_ext(350, 220, ""); /* Load and place the image first to have it in the background */ $image = $p->load_image("auto", $imagefile, ""); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_image($image, 0, 0, "scale=0.5"); /* Save the current graphics state */ $p->save(); /* Set the opacity in the current graphics state, * for the stamp to appear slightly transparent */ $gstate = $p->create_gstate("opacityfill=0.5"); $p->set_gstate($gstate); /* Fit the text line as outlines like a stamp in the specified box. * The stamp will be place diagonally from the lower left to the upper * right (stamp=ll2ur). It will be drawn in a transparent white * according to the opacity set for the current graphics state. */ $p->fit_textline("Our Test Image", 30, 10, "fontname=NotoSerif-Bold " . " fillcolor={rgb 1 1 1} boxsize={300 200} fontsize=1 stamp=ll2ur"); $p->restore(); $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=simple_stamp.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; ?>