Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: pdf_open_file - Manual
[go: Go Back, main page]

PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<pdf_open_CCITTpdf_open_gif" width="11" height="7"/>
view the version of this page
Last updated: Tue, 21 Dec 2004

pdf_open_file

(PHP 4 >= 4.0.5, PHP 5)

pdf_open_file -- 新規PDFオブジェクトをオープンする

説明

int pdf_open_file ( int pdf object [, string filename])

新規のPDFファイルを指定したファイル名で作成します。 filename が空の場合、PDFドキュメントはファ イルではなくメモリ上に作成されます。結果は、 pdf_get_buffer()関数によりクライアント側で取得 可能です。

PDFドキュメントをメモリ内に作成し、正しく出力する方法を示す例を以 下に示します。

例 1. PDFドキュメントをメモリ内に作成する

<?php

$pdf
= pdf_new();

pdf_open_file($pdf);
pdf_begin_page($pdf, 595, 842);
pdf_set_font($pdf, "Times-Roman", 30, "host");
pdf_set_value($pdf, "textrendering", 1);
pdf_show_xy($pdf, "A PDF document created in memory!", 50, 750);
pdf_end_page($pdf);
pdf_close($pdf);

$data = pdf_get_buffer($pdf);

header("Content-type: application/pdf");
header("Content-disposition: inline; filename=test.pdf");
header("Content-length: " . strlen($data));

echo
$data;

?>



add a note add a note User Contributed Notes
pdf_open_file
alfred dot zingg at freesurf dot ch at example dot com
17-Dec-2004 12:33
...
$fd = fopen("download/liste.pdf", "w");
$pdfdoc = pdf_open($fd);
pdf_begin_page($pdfdoc, 595, 842);
pdf_set_font($pdfdoc, "Helvetica", 20, "host", 1);
pdf_set_text_pos($pdfdoc, 50, 795);
pdf_show($pdfdoc, "Liste");
...
does not work under PHP5, use
...
$fd = fopen("download/liste.pdf", "w");
$pdfdoc = pdf_new();
pdf_open_file($pdfdoc, "download/liste.pdf");
pdf_begin_page($pdfdoc, 595.3, 841.8);
$font = pdf_findfont($pdfdoc, "Helvetica", "winansi", 0);
pdf_set_font($pdfdoc, $font, 20);
pdf_set_text_pos($pdfdoc, 50, 795);
pdf_show($pdfdoc, "Liste");
...
18-Oct-2004 09:55
After some troubles I found filename must be absolute path  here in windows; relative path doesn't work in my box.
php 4.3.5-dev
RandyAtHorktDotCom
29-Oct-2002 09:19
It is possible to append pdfs to each other, however it requires the commercial version of PDFlib with PDI support (http://www.pdflib.com)

I've used it quite a bit and is well worth the price they are asking for.
jon at logicworks dot cc
25-Oct-2002 03:48
When creating a pdf in memory, it appears that the code is executed twice. This does not seem to happen when creating a pdf as file. Not a problem when outputing a pdf, but does cause a problem if doing other writes in the same code:

// the write to the file is executed twice
$fp = fopen("testfile.htm", "a");
fwrite($fp, "testline/") ;
fclose($fp);
//--------------

$pdf = pdf_new();

if (!pdf_open_file($pdf, "")) {
   print error;
   exit;
};

pdf_begin_page($pdf, 8.5*72, 11*72);
pdf_set_font($pdf, "Helvetica-Bold", 24, "host");
pdf_set_text_pos($pdf, 50, 700);
pdf_show($pdf,"Hello,world!");
pdf_end_page($pdf);
pdf_close($pdf);

$buf = pdf_get_buffer($pdf);
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=foo.pdf");
print $buf;
gbl at bso2001 dot com
20-Feb-2002 04:30
Appending to PDF files: plainly, you can't. PDF files have an internal structure that would get corrupted by just appending to the file. You'd need to parse the PDF, create a new PDF and mix your additions with the old PDF. Just creating a new one should be *much* easier.

Reading back the results: do a fopen() on the temporary file and use fgets() to read it. In your example where you just want to output the file, passthru should do the trick.
nils at deviant dot no
16-Jan-2002 09:47
If you get "Fatal error: PDFlib error: function 'PDF_set_info' must not be called in 'object' scope in script.php on line xxx" when using pdf_open_file with a filename, make sure your webserver has write permissions to the directory your are trying to save your PDF file to.

<pdf_open_CCITTpdf_open_gif" width="11" height="7"/>
 Last updated: Tue, 21 Dec 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This mirror generously provided by: HappySize, Inc.
Last updated: Sat Jan 15 06:11:01 2005 JST