set_option("errorpolicy=exception searchPath={" . $searchpath . "}"); $p->begin_document("", "pdfua=PDF/UA-1 lang=en " . "tag={tagname=Document Title={" . $title . "} }") ; $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); /* Automatically create spaces between chunks of text */ $p->set_option("autospace=true"); $p->begin_page_ext(0, 0, "width=a4.width height=a4.height taborder=structure"); $p->create_bookmark("PDF/UA-1 demo", ""); $font = $p->load_font("NotoSerif-Regular", "unicode", ""); $p->setfont($font, 24.0); /* Create a P tag as container of text and link */ $id_P = $p->begin_item("P", ""); $p->fit_textline("The image serves as background for a link:", 50, 625, "fontsize=12"); /* ============== Link with background image =================== */ /* Create the Link element. The alternative text describes both * the background image and the link */ $id_Link = $p->begin_item("Link", "Alt={Visit Kraxi on the Web}"); $image = $p->load_image("auto", $imagefile, ""); /* The background image must be tagged as Artifact; the matchbox * provides the geometry for create_annotation() below. */ $p->fit_image($image, 50, 400, "tag={tagname=Artifact} scale=0.5 matchbox={name={kraxi}}"); $p->close_image($image); /* Create URI action */ $action = $p->create_action("URI", "url={http://www.kraxi.com}"); /* Create Link annotation on named matchbox "kraxi". * This automatically creates an OBJR (object reference) element * inside the Link element. */ $optlist = "linewidth=0 usematchbox={kraxi} " . "contents={Link to Kraxi Inc. Web site} " . "action={activate=" . $action . " } "; $p->create_annotation(0, 0, 0, 0, "Link", $optlist); /* Close the Link and P structure elements */ $p->end_item($id_Link); $p->end_item($id_P); $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=image_with_link_pdfua1.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in image_with_link_pdfua1 sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo($e); exit(1); } $p = 0; ?>