PDF_open_file

(PHP 4 >= 4.0.5, PECL pdflib >= 1.0.0)

PDF_open_fileCreate PDF file [deprecated]

Description

bool PDF_open_file ( resource $p , string $filename )

Creates a new PDF file using the supplied file name. Returns TRUE on success or FALSE on failure.

This function is deprecated since PDFlib version 6, use PDF_begin_document() instead.

Коментарии

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.
2002-01-16 06:47:10
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
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.
2002-02-19 13:30:57
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
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;
2002-10-24 14:48:49
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
Автор:
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.
2002-10-28 18:19:36
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
Автор:
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
2004-10-18 08:55:08
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
...
$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");
...
2004-12-16 09:33:01
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
The example uses pdf_set_font, but that function is deprecated. Instead use pdf_setfont (without the underscore).
2005-04-11 08:35:43
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
Автор:
"Fatal error: PDFlib error: [2100] PDF_begin_page: Function must not be called in 'object' scope.."

If you get this error then you probably forgot to call pdf_open_file() or pdf_open_file() failed.
2005-06-21 12:13:02
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
"Fatal error: PDFlib error: [2100] PDF_begin_page: Function must not be called in 'object' scope"

I found a solution for this fault: 
when i got the fault, this was the script -> 

<?php

$pdf 
pdf_new();

pdf_open_file($pdf"C:\web\pdf\test45.pdf");
pdf_begin_page($pdf595842);
pdf_set_font($pdf"Times-Roman"30"host");
pdf_set_value($pdf"textrendering"1);
pdf_show_xy($pdf"A PDF document is created!"50750);
pdf_end_page($pdf);
pdf_close($pdf);

?> 

but when i added some slashes to the path:

<?php

$pdf 
pdf_new();

pdf_open_file($pdf"C:\\web\\pdf\\test45.pdf");
pdf_begin_page($pdf595842);
pdf_set_font($pdf"Times-Roman"30"host");
pdf_set_value($pdf"textrendering"1);
pdf_show_xy($pdf"A PDF document is created!"50750);
pdf_end_page($pdf);
pdf_close($pdf);

?> 

there wasn't no fault anymore and the pdf-file was succesfully created

I think you guys get the point ( add 2 slashes )

Glenn
2005-08-10 12:39:58
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
FYI: the reason you had to add the double slashes was due to the fact that your string was contained within double quotes rather than single quotes.

See: http://ca3.php.net/manual/en/language.types.string.php
2007-04-24 01:21:57
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html
Автор:
you better use forward slashes in a path
2013-09-09 16:50:42
http://php5.kiev.ua/manual/ru/function.pdf-open-file.html

    Поддержать сайт на родительском проекте КГБ