set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); $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); $font = $p->load_font("Helvetica", "winansi", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* "Print"のイメージテンプレートをロードする */ $pimg = $p->load_image("auto", $p_imagefile, "template=true"); if ($pimg == 0) throw new Exception("Error: " . $p->get_errmsg()); /* "Save As" のイメージテンプレートをロードする */ $simg = $p->load_image("auto", $s_imagefile, "template=true"); if ($simg == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Acrobatのコマンド "File/Print"(ファイル/印刷)を実行するための *アクションを作成する */ $pact = $p->create_action("Named", "menuname=Print"); /* Acrobatのコマンド "File/Save As"(ファイル/名前を付けて保存)を * 実行するためのアクションを作成する */ $sact = $p->create_action("Named", "menuname=SaveAs"); /* ページを始める */ $p->begin_page_ext(0, 0, " width=a4.width height=a4.height"); $p->setfont($font, 14); /* ------------------------------------------------------------ * Acrobatメニューコマンドを実行するための2つのプッシュボタン * フィールドを生成し、キャプションを使用してそれを表す * ------------------------------------------------------------ */ /* 説明用テキストを出力する */ $p->fit_textline("Two buttons executing Acrobat menu commands and " . "represented by a caption:", $llx, $lly, ""); $lly-=60; /* "Print" と "Save" のプッシュボタンフォームフィールドを生成する * ライトブルーの背景色を持つボタンを指定する * (backgroundcolor={rgb 0.95 0.95 1}) and * 青の境界線を指定(bordercolor={rgb 0.25 0 0.95}) 線幅はデフォルト(1) * ボタンにテキスト「Print」を付け、文字を青で塗りつぶす * (caption={Print} fillcolor={rgb 0.25 0 0.95}). * 各ボタンにツールヒントを定義する * ユーザーがフィールドエリアからマウスボタンを離したときに実行される * アクション(アクションは上記で指定)を定義する * (action={up }). */ $optlist = "bordercolor={rgb 0.25 0 0.95} " . "backgroundcolor={rgb 0.95 0.95 1} " . "fillcolor={rgb 0.25 0 0.95} font=" . $font . " fontsize=14"; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "print", "pushbutton", $optlist . " caption={Print} action={up " . $pact . "} tooltip={Print the document}"); $llx+=100; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "save", "pushbutton", $optlist . " caption={Save As} action={up " . $sact . "} tooltip={Save the document}"); /* ------------------------------------------------------------ * Acrobatメニューコマンドを実行するための2つのプッシュボタン * フィールドを生成し、画像を使用してそれを表す * ------------------------------------------------------------ */ $llx=40; $lly=400; /* 説明用テキストを出力する */ $p->fit_textline("Two buttons executing Acrobat menu commands and " . "represented by an image:", $llx, $lly, ""); $lly-=60; /* "Print"イメージの幅と高さを取得する */ $pwidth = $p->info_image($pimg, "imagewidth", ""); $pheight = $p->info_image($pimg, "imageheight", ""); /* "Save"イメージの幅と高さを取得する */ $swidth = $p->info_image($simg, "imagewidth", ""); $sheight = $p->info_image($simg, "imageheight", ""); /* "printicon" と "saveicon" のプッシュボタンフォームフィールドを * 生成する * ボタンの高さだけではなく、画像の比率に基づいてボタンの幅を計算する * ユーザーがフィールドエリアからマウスボタンを離したときに実行される * アクション(アクションは上記で指定)を定義する * (action={up }). * 画像でボタンを指定する(icon=). * 各ボタンにツールヒントを定義する * 画像を長方形のボタンにはめ込んでください: Acrobatの特定の動作のため、 * 境界色の指定と、線幅をゼロにセットする必要がある */ $pbuttonwidth = $pwidth/$pheight*$height; $p->create_field($llx, $lly, $llx + $pbuttonwidth, $lly + $height, "printicon", "pushbutton", "action={up " . $pact . "} icon=" . $pimg . " tooltip={Print the document} bordercolor={gray 0} linewidth=0" . " font=" . $font); $llx+=100; $sbuttonwidth = $swidth/$sheight*$height; $p->create_field($llx, $lly, $llx + $sbuttonwidth, $lly + $height, "saveicon", "pushbutton", "action={up " . $sact . "} icon=" . $simg . " tooltip={Save the document} bordercolor={gray 0} linewidth=0" . " font=" . $font); $p->close_image($pimg); $p->close_image($simg); $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=form_pushbutton.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; ?>