set_option("searchpath={" . $searchpath . "}"); # load_font()の戻り値を確認する $p->set_option("errorpolicy=return"); $p->set_option("stringformat=utf8"); if ($p->begin_document("", "") == 0) { echo("Error: " . $p->get_errmsg()); exit(1); } $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); $font = $p->load_font("Helvetica", "unicode", ""); if ($font == 0) { echo("Error: " . $p->get_errmsg()); exit(1); } # 画像をロードする $image = $p->load_image("auto", $imagefile, ""); if ($image == 0) { echo("Error: " . $p->get_errmsg()); exit(1); } # 1 ページ目を始める $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $p->setfont($font, 12); # ------------------------------------ # 画像を元のサイズで配置する # ------------------------------------ # 左下隅を基準点 (20, 380) にして、元のサイズで画像を配置する。 $p->fit_image($image, 20, 380, ""); # 説明テキストを出力する $p->fit_textline( "The image is placed with the lower left corner in its original " . "size at reference point (20, 380):", 20, 820, ""); $p->fit_textline("fit_image(image, 20, 380, \"\");", 20, 800, ""); # -------------------------------------------------------- # 画像を左向きにして拡大縮小して配置する # -------------------------------------------------------- # 画像の右下隅が基準点 (580, 20) になるように配置する # "scale=0.5" は、画像を 0.5 倍に拡大する。 # "orientate=west" は画像を左に向ける。 $p->fit_image($image, 580, 20, "scale=0.5 position={right bottom} orientate=west"); # 説明テキストを出力する $p->fit_textline( "The image is placed with a scaling of 0.5 and an orientation to " . "the west with the lower right corner", 580, 320, "position={right bottom}"); $p->fit_textline( " at reference point (580, 20): fit_image(image, 580, 20, " . "\"scale=0.5 orientate=west position={right bottom}\");", 580, 300, "position={right bottom}"); $p->end_page_ext(""); # 2 ページ目を始める $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $p->setfont($font, 12); # ----------------------------------------------------- # クリッピングのあるボックスの中に画像をフィットさせる # ----------------------------------------------------- # "boxsize" オプションは、指定された幅と高さを持ち、左下隅が基準点にある # ボックスを定義する。 # "position={right top}" は、画像をボックスの右上に配置する。 # "fitmethod=clip"は、ボックスに収まるように画像をクリップする。 $buf = "boxsize={" . $bw . " " . $bh . "} position={right top} fitmethod=clip"; $p->fit_image($image, $x, $y, $buf); # 説明テキストを出力する $p->fit_textline( "fit_image(image, x, y, \"boxsize={400 200} position={right top} " . "fitmethod=clip\");", 20, $y+$bh+10, ""); # --------------------------------------------------- # 比例したサイズ変更で画像をボックスにフィットさせる # --------------------------------------------------- # "boxsize" オプションは、指定された幅と高さを持ち、左下隅が基準点にある # ボックスを定義する。 # "position={center}"は、画像を中央に配置する。 # "fitmethod=meet" は、高さまたは幅がボックスに完全に収まるまで、画像の # サイズを比例的に変更する。 # "showborder" オプションは、ボックスの境界を示すために使用される。 $buf = "boxsize={" . $bw . " " . $bh . "} position={center} fitmethod=meet showborder"; $p->fit_image($image, $x, $y-=$yoffset, $buf); # Output some descriptive text $p->fit_textline( "fit_image(image, x, y, \"boxsize={400 200} position={center} " . "fitmethod=meet showborder\");", 20, $y+$bh+10, ""); # --------------------------------- # 画像を枠内に完全にフィットさせる # --------------------------------- # The "boxsize" option defines a box with a given width and height and # its lower left corner located at the reference point. # By default, the image is positioned in the lower left corner of the # box. # "fitmethod=entire" resizes the image proportionally until its height # or width completely fits into the box. $buf = "boxsize={" . $bw . " " . $bh . "} fitmethod=entire"; $p->fit_image($image, $x, $y-=$yoffset, $buf); # Output some descriptive text $p->fit_textline( "fit_image(image, x, y, \"boxsize={400 200} fitmethod=entire\");", 20, $y+$bh+10, ""); $p->end_page_ext(""); $p->close_image($image); $p->end_document(""); $buf = $p->get_buffer(); $len = strlen($buf); header("Content-type: application/pdf"); header("Content-Length: $len"); header("Content-Disposition: inline; filename=starter_image.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in starter_image sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e); exit(1); } $p = 0; ?>