R&OS PDF in PHP (name of pdf)

情到浓时终转凉″ 提交于 2020-02-25 07:18:30

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/9497344/ros-pdf-in-php-name-of-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!