set_option("errorpolicy=return SearchPath={{" . $searchpath . "}}"); $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); /* * 透かしを作成する。デフォルトではドキュメント内の全てのページに * 適用する */ $p->begin_template_ext(0, 0, "watermark={location=ontop opacity=60%}"); $p->fit_textline("Preliminary", 0, 0, "fontsize=12 fontname=Helvetica-Bold encoding=unicode " . "fillcolor=red boxsize={595 842} stamp=ll2ur"); $p->end_template_ext(0, 0); /* * ページコンテンツを作成する */ $image = $p->load_image("auto", $imagefile, ""); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $p->fit_textline("The watermark can be edited in Acrobat", 20, 600, "fontname=Helvetica encoding=unicode fontsize=14"); $p->fit_image($image, 0.0, 0.0, "boxsize={595 600} fitmethod=meet"); $p->close_image($image); $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=text_on_color.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e->getMessage()); exit(1); } $p = 0; ?>