set_option("errorpolicy=return"); $p->set_option("searchpath={" . $searchpath . "}"); if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $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"); // Create template for use as annotation icon $tpl = $p->begin_template_ext($width, $height, ""); /* Load SVG graphics */ $graphics = $p->load_graphics("auto", $graphicsfile, ""); if ($graphics == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Place SVG in the lower left corner of the template */ $p->fit_graphics($graphics, 0, 0, "boxsize={ " . $width . " " . $height . "} position={center} fitmethod=meet"); $p->close_graphics($graphics); $p->end_template_ext(0, 0); // Create the annotation with template for "normal" appearance $p->create_annotation($llx, $lly, $llx+$width, $lly+$height, "Stamp", "template={normal=" . $tpl . "}"); $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=custom_stamp_annotation.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in stamp_annotation sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo($e); exit(1); } $p = 0; ?>