| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * http://www.lockon.co.jp/
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | /*----------------------------------------------------------------------
|
|---|
| 9 | * [̾¾Î] GC_Pdf
|
|---|
| 10 | * [³µÍ×] Pdf¥Õ¥¡¥¤¥ë¤òɽ¼¨¤¹¤ë¡£(PDFLibɬ¿Ü)
|
|---|
| 11 | *----------------------------------------------------------------------
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | // ¥°¥ê¥Ã¥É¤Èʸ»ú¤Î´Ö³Ö
|
|---|
| 15 | define("GRID_SPACE", 4);
|
|---|
| 16 |
|
|---|
| 17 | class SC_Pdf {
|
|---|
| 18 | var $arrText;
|
|---|
| 19 | var $arrImage;
|
|---|
| 20 | var $license_key;
|
|---|
| 21 | var $block_option;
|
|---|
| 22 | var $src_code;
|
|---|
| 23 | var $dst_code;
|
|---|
| 24 | var $pdiwarning;
|
|---|
| 25 | var $pdfpath;
|
|---|
| 26 | var $page_close;
|
|---|
| 27 |
|
|---|
| 28 | function SC_Pdf($width = 595, $height = 842, $fontsize = 10) {
|
|---|
| 29 | $this->license_key = "B600602-010400-714251-5851C1";
|
|---|
| 30 | $this->src_code = CHAR_CODE;
|
|---|
| 31 | // UTF-8¤Ç¤Ê¤¤¤È¥Ö¥í¥Ã¥¯Æâ¤Ç²þ¹Ô¤Ç¤¤Ê¤¤¡£
|
|---|
| 32 | $this->dst_code = "UTF-8";
|
|---|
| 33 | // PDF BLOCK¤Î¥×¥í¥Ñ¥Æ¥£
|
|---|
| 34 | $this->block_option = "encoding=UniJIS-UCS2-H textformat=utf8 fontname=HeiseiMin-W3 textflow=true";
|
|---|
| 35 | // ·Ù¹ðɽ¼¨
|
|---|
| 36 | $this->pdiwarning = "true";
|
|---|
| 37 | // ¥Ú¡¼¥¸¥µ¥¤¥ºÀßÄê
|
|---|
| 38 | $this->width = $width;
|
|---|
| 39 | $this->height = $height;
|
|---|
| 40 | // PDF½é´ü²½
|
|---|
| 41 | $this->pdf = PDF_new();
|
|---|
| 42 | PDF_set_parameter($this->pdf, "license", $this->license_key);
|
|---|
| 43 | PDF_set_parameter($this->pdf, "pdiwarning", $this->pdiwarning);
|
|---|
| 44 | // ¥É¥¥å¥á¥ó¥È³«»Ï
|
|---|
| 45 | PDF_begin_document($this->pdf, NULL, NULL);
|
|---|
| 46 | // ¥Ú¡¼¥¸¤Î¾õÂÖ
|
|---|
| 47 | $this->page_open = false;
|
|---|
| 48 | // ¥Æ¡¼¥Ö¥ë¤Î¿§ÀßÄê
|
|---|
| 49 | $this->setTableColor();
|
|---|
| 50 | // ¥Õ¥©¥ó¥È¥µ¥¤¥º¤ÎÀßÄê
|
|---|
| 51 | $this->fontsize = $fontsize;
|
|---|
| 52 | // ¥°¥ê¥Ã¥ÉÉÁ²è¤ÎÆÃ¼ì»ØÄê
|
|---|
| 53 | $this->arrLines = array();
|
|---|
| 54 | // ¥Æ¡¼¥Ö¥ë¥¿¥¤¥È¥ë¤Î¥¹¥¿¥¤¥ë
|
|---|
| 55 | $this->arrHeaderColSize = array();
|
|---|
| 56 | $this->arrHeaderAlign = array();
|
|---|
| 57 | // ¥Æ¡¼¥Ö¥ëÊäÀµÃÍ
|
|---|
| 58 | $this->table_left = 0;
|
|---|
| 59 | // ¥¿¥¤¥È¥ë¹Ô¤Î½ÐÎÏ
|
|---|
| 60 | $this->title_enable = true;
|
|---|
| 61 | // ¥°¥ê¥Ã¥É¤Î½ÐÎÏ
|
|---|
| 62 | $this->grid_enable = true;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | // ¥¿¥¤¥È¥ë¤ò½ÐÎϤ¹¤ë¤«Èݤ«
|
|---|
| 66 | function setTitleEnable($flag) {
|
|---|
| 67 | $this->title_enable = $flag;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | // ¥°¥ê¥Ã¥É¤ò½ÐÎϤ¹¤ë¤«Èݤ«
|
|---|
| 71 | function setGridEnable($flag) {
|
|---|
| 72 | $this->grid_enable = $flag;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | // ¥¡¼¡§¥Ö¥í¥Ã¥¯Ì¾¡¢ÃÍ¡§É½¼¨¥Æ¥¥¹¥È¤Î¥Ï¥Ã¥·¥åÇÛÎó¤ò¥»¥Ã¥È¤¹¤ë¡£
|
|---|
| 77 | function setTextBlock($list) {
|
|---|
| 78 | unset($this->arrText);
|
|---|
| 79 | $this->arrText[] = $list;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | // ¥¡¼¡§¥Ö¥í¥Ã¥¯Ì¾¡¢ÃÍ¡§¥Õ¥¡¥¤¥ë¥Ñ¥¹¤Î¥Ï¥Ã¥·¥åÇÛÎó¤ò¥»¥Ã¥È¤¹¤ë¡£
|
|---|
| 83 | // ¢¨¥Ñ¥¹¤Ï¥É¥¥å¥á¥ó¥È¥ë¡¼¥È°Ê²¼
|
|---|
| 84 | function setImageBlock($list) {
|
|---|
| 85 | unset($this->arrImage);
|
|---|
| 86 | $this->arrImage[] = $list;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | // ɽ¼¨ÇØ·Ê¤È¤Ê¤ë¥Æ¥ó¥×¥ì¡¼¥È¥Õ¥¡¥¤¥ë¥Ñ¥¹
|
|---|
| 90 | // ¢¨¥Ñ¥¹¤Ï¥É¥¥å¥á¥ó¥È¥ë¡¼¥È°Ê²¼
|
|---|
| 91 | function setTemplate($pdfpath) {
|
|---|
| 92 | if(file_exists($pdfpath)) {
|
|---|
| 93 | $this->pdfpath = $pdfpath;
|
|---|
| 94 | } else {
|
|---|
| 95 | print("»ØÄꤷ¤¿PDF¥Æ¥ó¥×¥ì¡¼¥È¤Ï¸ºß¤·¤Þ¤»¤ó¡§".$pdfpath);
|
|---|
| 96 | exit;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | // ¥Æ¡¼¥Ö¥ë°ÌÃÖÊäÀµÃÍ
|
|---|
| 101 | function setTableLeft($table_left) {
|
|---|
| 102 | $this->table_left = $table_left;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | // ¥°¥ê¥Ã¥ÉÉÁ²è¤ÎÆÃ¼ì»ØÄê
|
|---|
| 106 | function setGridLines($list) {
|
|---|
| 107 | $this->arrLines = $list;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | // ¥Æ¡¼¥Ö¥ë¥¿¥¤¥È¥ë¤Î¥¹¥¿¥¤¥ëÀßÄê
|
|---|
| 111 | function setTableHeaderStyle($arrColSize, $arrAlign) {
|
|---|
| 112 | $this->arrHeaderColSize = $arrColSize;
|
|---|
| 113 | $this->arrHeaderAlign = $arrAlign;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // ¥Ö¥í¥Ã¥¯¥Ç¡¼¥¿¤Î½ñ¤¹þ¤ß(close¤¹¤ë¤È¼¡²ó¿·µ¬¥Ú¡¼¥¸)
|
|---|
| 117 | function writeBlock() {
|
|---|
| 118 | // ¥Æ¥ó¥×¥ì¡¼¥È¤ò»ÈÍѤ¹¤ë
|
|---|
| 119 | if(!file_exists($this->pdfpath)) {
|
|---|
| 120 | return;
|
|---|
| 121 | }
|
|---|
| 122 | // ´û¸PDF¤Î¥É¥¥å¥á¥ó¥È¤ò¼èÆÀ
|
|---|
| 123 | $doc = pdf_open_pdi($this->pdf, $this->pdfpath, NULL, 0 );
|
|---|
| 124 | // ´û¸PDF¤Î¥É¥¥å¥á¥ó¥È¤«¤é»ØÄê¥Ú¡¼¥¸¤ò¼èÆÀ
|
|---|
| 125 | $page = pdf_open_pdi_page($this->pdf, $doc, 1, NULL );
|
|---|
| 126 | // ¥Ú¡¼¥¸¤ò³«¤¯
|
|---|
| 127 | $this->openPage();
|
|---|
| 128 |
|
|---|
| 129 | // ´û¸PDF¤Î¥Ú¡¼¥¸¤ò³ä¤êÅö¤Æ¤ë
|
|---|
| 130 | PDF_fit_pdi_page($this->pdf, $page, 0, 0, "adjustpage");
|
|---|
| 131 |
|
|---|
| 132 | // ¥Æ¥¥¹¥È¥Ö¥í¥Ã¥¯¤Î½ñ¤¹þ¤ß
|
|---|
| 133 | $max = count($this->arrText);
|
|---|
| 134 | for($i = 0;$i < $max; $i++) {
|
|---|
| 135 | foreach($this->arrText[$i] as $key => $val) {
|
|---|
| 136 | if($val != "") {
|
|---|
| 137 | // ʸ»ú¥³¡¼¥É¤ÎÊÑ´¹
|
|---|
| 138 | mb_convert_variables($this->dst_code, $this->src_code, $val);
|
|---|
| 139 | // ½ñ¤¹þ¤ß
|
|---|
| 140 | $ret = PDF_fill_textblock($this->pdf, $page, $key, $val, $this->block_option);
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | // ¥¤¥á¡¼¥¸¥Ö¥í¥Ã¥¯¤Î½ñ¤¹þ¤ß
|
|---|
| 146 | $max = count($this->arrImage);
|
|---|
| 147 | for($i = 0;$i < $max; $i++) {
|
|---|
| 148 | foreach($this->arrImage[$i] as $key => $val) {
|
|---|
| 149 | if($val != "") {
|
|---|
| 150 | $img = PDF_load_image($this->pdf, "auto", $val, NULL );
|
|---|
| 151 | $ret = PDF_fill_imageblock($this->pdf, $page, $key, $img, NULL);
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 | // ³ä¤êÅö¤Æ¤¿¥Ú¡¼¥¸¤òÊĤ¸¤ë
|
|---|
| 157 | PDF_close_pdi_page($this->pdf, $page);
|
|---|
| 158 | // ³ä¤êÅö¤Æ¤¿¥É¥¥å¥á¥ó¥È¤òÊĤ¸¤ë
|
|---|
| 159 | PDF_close_pdi($this->pdf, $doc);
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | // ¥Ú¡¼¥¸¤òÊĤ¸¤ë
|
|---|
| 163 | function closePage() {
|
|---|
| 164 | if($this->page_open) {
|
|---|
| 165 | // ¥Ú¡¼¥¸¤òÊĤ¸¤ë
|
|---|
| 166 | PDF_end_page_ext($this->pdf, NULL);
|
|---|
| 167 | $this->page_open = false;
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | // ¥Ú¡¼¥¸¤ò³«¤¯
|
|---|
| 172 | function openPage() {
|
|---|
| 173 | if(!$this->page_open) {
|
|---|
| 174 | // ¿·¤·¤¤¥Ú¡¼¥¸¤ò³«¤¯
|
|---|
| 175 | PDF_begin_page_ext($this->pdf, $this->width, $this->height, NULL);
|
|---|
| 176 | $this->page_open = true;
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | // ¿·¤·¤¤¥Ú¡¼¥¸¤ò³«¤¯
|
|---|
| 181 | function newPage() {
|
|---|
| 182 | PDF_end_page_ext($this->pdf, NULL);
|
|---|
| 183 | PDF_begin_page_ext($this->pdf, $this->width, $this->height, NULL);
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | // ¥¢¥¯¥Æ¥£¥Ö¤Ê¥Ú¡¼¥¸¤Î¥µ¥¤¥º¤ò¼èÆÀ¤¹¤ë
|
|---|
| 187 | function getSize() {
|
|---|
| 188 | $this->openPage();
|
|---|
| 189 | $x = PDF_get_value($this->pdf, 'pagewidth', 0);
|
|---|
| 190 | $y = PDF_get_value($this->pdf, 'pageheight', 0);
|
|---|
| 191 | return array($x, $y);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // ºÂɸ¤òÆþ¤ìÂØ¤¨¤Æ¼èÆÀ¤¹¤ë(º¸²¼(0,0)¤òº¸¾å(0,0)¤ËÊÑ´¹)
|
|---|
| 195 | function posTopDown($x, $y) {
|
|---|
| 196 | $width = 0;
|
|---|
| 197 | $height = 0;
|
|---|
| 198 | list($width, $height) = $this->getSize();
|
|---|
| 199 | // xºÂɸ¤Ï¡¢Êѹ¹¤ÎɬÍפʤ·
|
|---|
| 200 | $pdf_x = $x;
|
|---|
| 201 | $pdf_y = $height - $y;
|
|---|
| 202 | return array($pdf_x, $pdf_y);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | // ¥Æ¡¼¥Ö¥ë¥«¥é¡¼¤ÎÀßÄê
|
|---|
| 206 | function setTableColor($frame_color = "000000", $title_color = "F0F0F0", $line_color = "D1DEFE", $last_color = "FDCBFE") {
|
|---|
| 207 | $this->frame_color = $frame_color;
|
|---|
| 208 | $this->title_color = $title_color;
|
|---|
| 209 | $this->line_color = $line_color;
|
|---|
| 210 | $this->last_color = $last_color;
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | // ¥Æ¡¼¥Ö¥ë¤Î¥°¥ê¥Ã¥É¤òɽ¼¨¤¹¤ë¡£
|
|---|
| 214 | function writeGrid($x, $y, $arrCol, $line_max, $last_color_flg = true) {
|
|---|
| 215 | // ¥Æ¡¼¥Ö¥ëÉý
|
|---|
| 216 | $max = count($arrCol);
|
|---|
| 217 | $width = 0;
|
|---|
| 218 | for($i = 0; $i < $max; $i++) {
|
|---|
| 219 | $width += $arrCol[$i];
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | if($this->title_enable) {
|
|---|
| 223 | // ¥¿¥¤¥È¥ë¥°¥ê¥Ã¥ÉÉÁ²è
|
|---|
| 224 | $this->writeFrameRect($x, $y + GRID_SPACE, $width + GRID_SPACE, $this->fontsize + GRID_SPACE, $this->title_color, $this->frame_color);
|
|---|
| 225 | }
|
|---|
| 226 |
|
|---|
| 227 | // ¥°¥ê¥Ã¥ÉÆÃ¼ì»ØÄꤢ¤ê
|
|---|
| 228 | if(count($this->arrLines) > 0) {
|
|---|
| 229 | $count = count($this->arrLines);
|
|---|
| 230 | $pos = 0;
|
|---|
| 231 | for($i = 0; $i < $count; $i++) {
|
|---|
| 232 | if(($i % 2) != 0) {
|
|---|
| 233 | // ¹Ô¤Î´Ö³Ö
|
|---|
| 234 | $down = ($pos + 1) * $this->fontsize * 1.5;
|
|---|
| 235 | // ÉÁ²è¤¹¤ë½ÄÉý¤òµá¤á¤ë
|
|---|
| 236 | $height = ($this->fontsize + GRID_SPACE) * $this->arrLines[$i] + ($this->arrLines[$i] - 1);
|
|---|
| 237 | // ¹Ô¥°¥ê¥Ã¥ÉÉÁ²è
|
|---|
| 238 | $this->writeRect($x, $y + GRID_SPACE + $down, $width + GRID_SPACE, $height, $this->line_color);
|
|---|
| 239 | }
|
|---|
| 240 | $pos += $this->arrLines[$i];
|
|---|
| 241 | }
|
|---|
| 242 | } else {
|
|---|
| 243 | for($i = 1; $i <= $line_max; $i++) {
|
|---|
| 244 | if(($i % 2) == 0) {
|
|---|
| 245 | // ¹Ô¤Î´Ö³Ö
|
|---|
| 246 | $down = $i * $this->fontsize * 1.5;
|
|---|
| 247 | // ¹Ô¥°¥ê¥Ã¥ÉÉÁ²è
|
|---|
| 248 | $this->writeRect($x, $y + GRID_SPACE + $down, $width + GRID_SPACE, $this->fontsize + GRID_SPACE, $this->line_color);
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 | // ºÇ½ª¹Ô¤Ë¿§¤ò¤Ä¤±¤ë¾ì¹ç
|
|---|
| 252 | if($last_color_flg) {
|
|---|
| 253 | // ¹Ô¤Î´Ö³Ö
|
|---|
| 254 | $down = $line_max * $this->fontsize * 1.5;
|
|---|
| 255 | // ¹Ô¥°¥ê¥Ã¥ÉÉÁ²è
|
|---|
| 256 | $this->writeRect($x, $y + GRID_SPACE + $down, $width + GRID_SPACE, $this->fontsize + GRID_SPACE, $this->last_color);
|
|---|
| 257 | }
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | // ¥°¥ê¥Ã¥ÉÍѤΥ¢¥ó¥À¡¼¥é¥¤¥ó¤ò°ú¤¯
|
|---|
| 262 | /*
|
|---|
| 263 | $x :¥Æ¡¼¥Ö¥ë³«»Ï°ÌÃÖX¼´
|
|---|
| 264 | $y :¥Æ¡¼¥Ö¥ë³«»Ï°ÌÃÖY¼´
|
|---|
| 265 | $arrCol :¥«¥é¥à¥µ¥¤¥º¤ÎÇÛÎó
|
|---|
| 266 | $line :¥¢¥ó¥À¡¼¥é¥¤¥ó¤ò°ú¤¯¹Ô
|
|---|
| 267 | $start_col :¥¢¥ó¥À¡¼¥é¥¤¥ó³«»Ï¥«¥é¥à(0:³«»Ï¥«¥é¥à)
|
|---|
| 268 | */
|
|---|
| 269 | function writeUnderLine($x, $y, $arrCol, $line, $start_col = 0) {
|
|---|
| 270 | // ¥Æ¡¼¥Ö¥ëÉý
|
|---|
| 271 | $max = count($arrCol);
|
|---|
| 272 | $width = 0;
|
|---|
| 273 | for($i = 0; $i < $max; $i++) {
|
|---|
| 274 | $width += $arrCol[$i];
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | $start_x = 0;
|
|---|
| 278 | for($i = 0; $i < $start_col; $i++) {
|
|---|
| 279 | $start_x += $arrCol[$i];
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | // ¥¢¥ó¥À¡¼¥é¥¤¥ó¤ÎYºÂɸ¤òµá¤á¤ë
|
|---|
| 283 | $down = ($line + 1) * $this->fontsize * 1.5;
|
|---|
| 284 | // ¹Ô¥°¥ê¥Ã¥ÉÉÁ²è
|
|---|
| 285 | $sx = $x + $start_x + GRID_SPACE + $this->table_left;
|
|---|
| 286 | $sy = $y + GRID_SPACE + $down - 1;
|
|---|
| 287 | $ex = $x + $width + GRID_SPACE;
|
|---|
| 288 | $ey = $sy;
|
|---|
| 289 |
|
|---|
| 290 | $this->writeLine($sx, $sy, $ex, $ey);
|
|---|
| 291 | }
|
|---|
| 292 |
|
|---|
| 293 | // ¿¿¤óÃæ²£°ÌÃÖ¤òµá¤á¤ë
|
|---|
| 294 | function getXCenter($width) {
|
|---|
| 295 | $page_width = 0;
|
|---|
| 296 | $page_height = 0;
|
|---|
| 297 | list($page_width, $page_height) = $this->getSize();
|
|---|
| 298 | $x = ($page_width - $width) / 2;
|
|---|
| 299 | return $x;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | // ¼«Æ°Ãæ±û¤è¤»
|
|---|
| 303 | function writeTableCenter($table, $y, $arrCol, $arrAlign, $line_max = 256, $start_no = 1, $last_color_flg = false) {
|
|---|
| 304 | // ¥Æ¡¼¥Ö¥ë¥µ¥¤¥º¼èÆÀ
|
|---|
| 305 | $width = 0;
|
|---|
| 306 | foreach($arrCol as $val) {
|
|---|
| 307 | $width += $val;
|
|---|
| 308 | }
|
|---|
| 309 | // Ãæ±û¤è¤»°ÌÃÖ¼èÆÀ
|
|---|
| 310 | $x = $this->getXCenter($width) + $this->table_left;
|
|---|
| 311 | list($ret_x, $ret_y) = $this->writeTable($table, $x, $y, $arrCol, $arrAlign, $line_max, $start_no, $last_color_flg);
|
|---|
| 312 | // X¼´¤ÎºÂɸ¤òÊÖ¤¹
|
|---|
| 313 | return array($ret_x, $ret_y);
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | // ¥Ç¡¼¥¿¤Î½ñ¤¹þ¤ß(close¤¹¤ë¤È¼¡²ó¿·µ¬¥Ú¡¼¥¸)
|
|---|
| 317 | // $start_no:1¹ÔÌÜ(¥¿¥¤¥È¥ë)¤ò0¤È¤¹¤ë¡£
|
|---|
| 318 | // $line_max:¥¿¥¤¥È¥ë¤ò´Þ¤Þ¤Ê¤¤¹Ô¿ô
|
|---|
| 319 | function writeTable($table, $x, $y, $arrCol, $arrAlign, $line_max = 256, $start_no = 1, $last_color_flg = false) {
|
|---|
| 320 | $this->openPage();
|
|---|
| 321 |
|
|---|
| 322 | $table = ereg_replace("\n$", "", $table);
|
|---|
| 323 |
|
|---|
| 324 | $arrRet = split("\n", $table);
|
|---|
| 325 |
|
|---|
| 326 | if($line_max > (count($arrRet) - $start_no)) {
|
|---|
| 327 | $line_max = count($arrRet) - $start_no;
|
|---|
| 328 | }
|
|---|
| 329 |
|
|---|
| 330 | // ¥¿¥¤¥È¥ë͸ú
|
|---|
| 331 | if($this->grid_enable) {
|
|---|
| 332 | // ¥°¥ê¥Ã¥É¤ÎÉÁ²è
|
|---|
| 333 | $this->writeGrid($x, $y, $arrCol, $line_max, $last_color_flg);
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|
| 336 | // Unicode¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤È¤·¤ÆUTF-8¤òÀßÄê
|
|---|
| 337 | PDF_set_parameter($this->pdf, "textformat", "utf8");
|
|---|
| 338 |
|
|---|
| 339 | // ¥¿¥¤¥È¥ë͸ú
|
|---|
| 340 | if($this->title_enable) {
|
|---|
| 341 | if(count($this->arrHeaderColSize) > 0 && count($this->arrHeaderAlign) > 0 ) {
|
|---|
| 342 | list($linecol, $aligncol, $width) = $this->getTableOption($this->arrHeaderColSize, $this->arrHeaderAlign);
|
|---|
| 343 | } else {
|
|---|
| 344 | list($linecol, $aligncol, $width) = $this->getTableOption($arrCol, $arrAlign);
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | // ¥¿¥¤¥È¥ë¹Ô¤Î½ñ¤¹þ¤ß
|
|---|
| 348 | $option = "ruler {" . $linecol . "} ";
|
|---|
| 349 | $option.= "tabalignment {" . $aligncol . "} ";
|
|---|
| 350 | $fontsize = $this->fontsize;
|
|---|
| 351 | $option.= "hortabmethod ruler leading=150% fontname=HeiseiKakuGo-W5 fontsize=$fontsize encoding=UniJIS-UCS2-H";
|
|---|
| 352 |
|
|---|
| 353 | $this->writeTableData($table, $x, $y, $width, 0, 0, $option);
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | list($linecol, $aligncol, $width) = $this->getTableOption($arrCol, $arrAlign);
|
|---|
| 357 |
|
|---|
| 358 | // ¥Ç¡¼¥¿¹Ô¤Î½ñ¤¹þ¤ß
|
|---|
| 359 | $option = "ruler {" . $linecol . "} ";
|
|---|
| 360 | $option.= "tabalignment {" . $aligncol . "} ";
|
|---|
| 361 | $option.= "hortabmethod ruler leading=150% fontname=HeiseiMin-W3 fontsize=$this->fontsize encoding=UniJIS-UCS2-H";
|
|---|
| 362 |
|
|---|
| 363 | if($start_no <= 0) {
|
|---|
| 364 | $start_no = 1;
|
|---|
| 365 | $end_no = $line_max;
|
|---|
| 366 | } else {
|
|---|
| 367 | $end_no = $start_no + $line_max - 1;
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | $y += $this->fontsize * 1.5;
|
|---|
| 371 |
|
|---|
| 372 | list($ret_x, $ret_y) = $this->writeTableData($table, $x, $y, $width, $start_no, $end_no, $option);
|
|---|
| 373 |
|
|---|
| 374 | return array($ret_x, $ret_y);
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | function getTableOption($arrCol, $arrAlign) {
|
|---|
| 378 | // ¥«¥é¥à¥µ¥¤¥º
|
|---|
| 379 | $max = count($arrCol);
|
|---|
| 380 | $width = 0;
|
|---|
| 381 | for($i = 0; $i < $max; $i++) {
|
|---|
| 382 | $width += $arrCol[$i];
|
|---|
| 383 | $linecol.= $width . " ";
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | // ¥«¥é¥à°ÌÃÖ
|
|---|
| 387 | $max = count($arrAlign);
|
|---|
| 388 | for($i = 0; $i < $max; $i++) {
|
|---|
| 389 | $aligncol.= $arrAlign[$i] . " ";
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | return array($linecol, $aligncol, $width);
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | // ¥Æ¡¼¥Ö¥ë¥Ç¡¼¥¿¤Î½ñ¤¹þ¤ß
|
|---|
| 396 | function writeTableData($table, $x, $y, $table_width, $start_no, $end_no, $option) {
|
|---|
| 397 | $arrLine = split("\n", $table);
|
|---|
| 398 | for($i = $start_no; $i <= $end_no; $i++) {
|
|---|
| 399 | $line.=$arrLine[$i] . "\n";
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | // ¥Æ¡¼¥Ö¥ë°ÌÃÖ¤òµá¤á¤ë
|
|---|
| 403 | list($pdf_x, $pdf_y) = $this->posTopDown($x, $y);
|
|---|
| 404 |
|
|---|
| 405 | // ¥Æ¡¼¥Ö¥ë¹â¤µ¤òµá¤á¤ë
|
|---|
| 406 | $table_height = $this->fontsize * 1.5 * ($end_no - $start_no + 1);
|
|---|
| 407 | // ¥Æ¡¼¥Ö¥ë±¦²¼¤ÎyºÂɸ¤òµá¤á¤ë
|
|---|
| 408 | $end_y = $pdf_y - $table_height;
|
|---|
| 409 | if($end_y < 0) {
|
|---|
| 410 | $end_y = 0;
|
|---|
| 411 | }
|
|---|
| 412 | $enc_table = mb_convert_encoding($line, "utf-8", CHAR_CODE);
|
|---|
| 413 |
|
|---|
| 414 | $tf = PDF_create_textflow($this->pdf, $enc_table, $option);
|
|---|
| 415 |
|
|---|
| 416 | PDF_fit_textflow($this->pdf, $tf, $pdf_x, $pdf_y, $pdf_x + $table_width, $end_y, NULL);
|
|---|
| 417 | PDF_delete_textflow($this->pdf, $tf);
|
|---|
| 418 |
|
|---|
| 419 | // ¥Æ¡¼¥Ö¥ëº¸²¼ºÂɸ¤òÊÖ¤¹
|
|---|
| 420 | return array($x, $y + $table_height);
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | // ¿§¤ÎÀßÄê
|
|---|
| 424 | function setColor($rgb) {
|
|---|
| 425 | if($rgb != "") {
|
|---|
| 426 | list($r, $g, $b) = sfGetPdfRgb($rgb);
|
|---|
| 427 | PDF_setcolor($this->pdf, "fillstroke", "rgb", $r, $g, $b, 0);
|
|---|
| 428 | }
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | // û·Á¤òÉÁ²è
|
|---|
| 432 | function writeRect($x, $y, $width, $height, $rgb = "") {
|
|---|
| 433 | $this->openPage();
|
|---|
| 434 | list($pdf_x, $pdf_y) = $this->posTopDown($x, $y);
|
|---|
| 435 | $this->setColor($rgb);
|
|---|
| 436 | PDF_rect($this->pdf, $pdf_x,$pdf_y,$width,-$height);
|
|---|
| 437 | PDF_fill($this->pdf);
|
|---|
| 438 | }
|
|---|
| 439 |
|
|---|
| 440 | // ÏÈÉÕ¤Îû·Á¤òÉÁ²è
|
|---|
| 441 | function writeFrameRect($x, $y, $width, $height, $rgb, $frgb) {
|
|---|
| 442 | $this->openPage();
|
|---|
| 443 | list($pdf_x, $pdf_y) = $this->posTopDown($x, $y);
|
|---|
| 444 | $this->setColor($frgb);
|
|---|
| 445 | PDF_rect($this->pdf, $pdf_x,$pdf_y,$width,-$height);
|
|---|
| 446 | PDF_fill($this->pdf);
|
|---|
| 447 |
|
|---|
| 448 | $this->setColor($rgb);
|
|---|
| 449 | PDF_rect($this->pdf, $pdf_x+1,$pdf_y-1,$width-2,-$height+2);
|
|---|
| 450 | PDF_fill($this->pdf);
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | // ľÀþ¤òÉÁ²è
|
|---|
| 454 | function writeLine($sx, $sy, $ex, $ey, $rgb = "000000") {
|
|---|
| 455 | $this->openPage();
|
|---|
| 456 | list($pdf_sx, $pdf_sy) = $this->posTopDown($sx, $sy);
|
|---|
| 457 | list($pdf_ex, $pdf_ey) = $this->posTopDown($ex, $ey);
|
|---|
| 458 | $this->setColor($rgb);
|
|---|
| 459 | PDF_setlinewidth($this->pdf, 1.0);
|
|---|
| 460 | PDF_moveto($this->pdf, $pdf_sx, $pdf_sy);
|
|---|
| 461 | PDF_lineto($this->pdf, $pdf_ex, $pdf_ey);
|
|---|
| 462 | PDF_stroke($this->pdf);
|
|---|
| 463 | }
|
|---|
| 464 |
|
|---|
| 465 | // ¥Õ¥¡¥¤¥ë¤Î¥À¥¦¥ó¥í¡¼¥É
|
|---|
| 466 | function output($filekey = "") {
|
|---|
| 467 | if(isset($this->pdf)) {
|
|---|
| 468 | // ¥Ú¡¼¥¸¤òÊĤ¸¤ë
|
|---|
| 469 | $this->closePage();
|
|---|
| 470 | // PDF¤Î½ªÎ»
|
|---|
| 471 | PDF_end_document($this->pdf, NULL);
|
|---|
| 472 | // ½ÐÎÏÍѥǡ¼¥¿¤Î¼èÆÀ
|
|---|
| 473 | $buf = PDF_get_buffer($this->pdf);
|
|---|
| 474 | $filename = $filekey . date("ymdHis").".pdf";
|
|---|
| 475 |
|
|---|
| 476 | header("Content-disposition: attachment; filename=$filename");
|
|---|
| 477 | header("Content-type: application/octet-stream; name=$filename");
|
|---|
| 478 |
|
|---|
| 479 | /*
|
|---|
| 480 | * session_start()¤ò»öÁ°¤Ë¸Æ¤Ó½Ð¤·¤Æ¤¤¤ë¾ì¹ç¤Ë½ÐÎϤµ¤ì¤ë°Ê²¼¤Î¥Ø¥Ã¥À¤Ï¡¢
|
|---|
| 481 | * URLľÀܸƤӽФ·»þ¤Ë¥¨¥é¡¼¤òȯÀ¸¤µ¤»¤ë¤Î¤Ç¶õ¤Ë¤·¤Æ¤ª¤¯¡£
|
|---|
| 482 | *
|
|---|
| 483 | * Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
|---|
| 484 | * Progma: no-cache
|
|---|
| 485 | *
|
|---|
| 486 | */
|
|---|
| 487 | header("Cache-Control: ");
|
|---|
| 488 | header("Pragma: ");
|
|---|
| 489 | print $buf;
|
|---|
| 490 |
|
|---|
| 491 | // PDF²òÊü
|
|---|
| 492 | PDF_delete($this->pdf);
|
|---|
| 493 | } else {
|
|---|
| 494 | print("PDF¤¬À¸À®¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
|
|---|
| 495 | }
|
|---|
| 496 | exit;
|
|---|
| 497 | }
|
|---|
| 498 |
|
|---|
| 499 | // ¥Õ¥¡¥¤¥ë¤Îɽ¼¨
|
|---|
| 500 | function display() {
|
|---|
| 501 | if(isset($this->pdf)) {
|
|---|
| 502 | // ¥Ú¡¼¥¸¤òÊĤ¸¤ë
|
|---|
| 503 | $this->closePage();
|
|---|
| 504 | // PDF¤Î½ªÎ»
|
|---|
| 505 | PDF_end_document($this->pdf, NULL);
|
|---|
| 506 |
|
|---|
| 507 | // ½ÐÎÏÍѥǡ¼¥¿¤Î¼èÆÀ
|
|---|
| 508 | $buf = PDF_get_buffer($this->pdf);
|
|---|
| 509 | $len = strlen($buf);
|
|---|
| 510 | header("Content-type: application/pdf");
|
|---|
| 511 | header("Content-Length: $len");
|
|---|
| 512 | header("Content-Disposition: inline; filename=". date("YmdHis").".pdf");
|
|---|
| 513 |
|
|---|
| 514 | /*
|
|---|
| 515 | * session_start()¤ò»öÁ°¤Ë¸Æ¤Ó½Ð¤·¤Æ¤¤¤ë¾ì¹ç¤Ë½ÐÎϤµ¤ì¤ë°Ê²¼¤Î¥Ø¥Ã¥À¤Ï¡¢
|
|---|
| 516 | * URLľÀܸƤӽФ·»þ¤Ë¥¨¥é¡¼¤òȯÀ¸¤µ¤»¤ë¤Î¤Ç¶õ¤Ë¤·¤Æ¤ª¤¯¡£
|
|---|
| 517 | *
|
|---|
| 518 | * Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
|---|
| 519 | * Progma: no-cache
|
|---|
| 520 | *
|
|---|
| 521 | */
|
|---|
| 522 | header("Cache-Control: ");
|
|---|
| 523 | header("Pragma: ");
|
|---|
| 524 | print $buf;
|
|---|
| 525 |
|
|---|
| 526 | // PDF²òÊü
|
|---|
| 527 | PDF_delete($this->pdf);
|
|---|
| 528 | } else {
|
|---|
| 529 | print("PDF¤¬À¸À®¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£");
|
|---|
| 530 | }
|
|---|
| 531 | exit;
|
|---|
| 532 | }
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | ?> |
|---|