source: temp/trunk/data/class/SC_Pdf.php @ 1328

Revision 1328, 14.3 KB checked in by naka, 20 years ago (diff)

* empty log message *

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