Minucioso
Minucioso

Reputation: 607

R&OS PDF in PHP (name of pdf)

anyone uses this function to create PDF in PHP?

http://www.ros.co.nz/pdf/

I need set the name of this pdf, and I don't find the option. The name is the same of the current page; for example if the page is www.myweb.com/hello.php the name will be hello.pdf. I need change this name with an unique name for each pdf because it is for billing.

This is an example of the code:

<?php
include('class.ezpdf.php');
$pdf =& new Cezpdf('a4');
$pdf->selectFont('fonts/courier.afm');
$datacreator = array (
                    'Title'=>'Factura PDF',
                    'Author'=>'Just me',
                    'Subject'=>'Factura nº123123123',
                    'Creator'=>'Just me',
                    'Producer'=>'http://www.xxxxxxx.com'
                    );
$pdf->addInfo($datacreator);
$pdf->ezText("<b>Factura numero 123123123 </b>\n",20);
$pdf->ezText("Esta es una prueba de pdf\n",12);
$pdf->ezText("\n\n\n",10);
$pdf->ezText("<b>Fecha:</b> ".date("d/m/Y"),10);
$pdf->ezText("<b>Hora:</b> ".date("H:i:s")."\n\n",10);
$pdf->ezStream();
?>

Thanks.

Upvotes: 1

Views: 4380

Answers (4)

Otavio de Souza Rocha
Otavio de Souza Rocha

Reputation: 203

The documentation said to do like this: $pdf->ezStream(array('filename'=>$nome,'compress'=>0)); but, nothing happen for me.

Upvotes: 0

Erwin
Erwin

Reputation: 71

Don't use $pdf->ezStream() or $pdf->stream(), use $pdf->output() instead. Try to add following codes to the bottom of your PHP code:

header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=yourfilename.pdf");
print $pdf->output();

Hope it helps.

Upvotes: 1

axiomer
axiomer

Reputation: 2126

This might work (not tested though):

Based on the FAQ, $pdfcode = $pdf->ezOutput(); makes the PDF's code itself. Write it to a whatever.pdf file where whatever is the desired file.

Upvotes: 0

tleilax
tleilax

Reputation: 94

Apparently, the filename can only be set via http headers and the author of the library is not sure whether it works or not. The documention for stream() states:

The options array can be used to set a number of things about the output:

'Content-Disposition'=>'filename' sets the filename, though not too sure how well this will work as in my trial the browser seems to use the filename of the php file with .pdf on the end.

Upvotes: 0

Related Questions