我正在使用TCPDF打印收据,然后使用phpMailer将其发送给客户,但是我遇到了问题:
我不知道如何将文件保存为pdf。
我已经试过了:
// reset pointer to the last page
$pdf->lastPage();
//Close and output PDF document
$pdf->Output('kuitti'.$ordernumber.'.pdf', 'I');
$this->Output("kuitit");
尝试这个
$pdf->Output('kuitti'.$ordernumber.'.pdf', 'F');
它将生成的pdf文件存储在项目的自定义文件夹中
$filename= "{$membership->id}.pdf";
$filelocation = "D:\\wamp\\www\\project\\custom";//windows
$filelocation = "/var/www/project/custom"; //Linux
$fileNL = $filelocation."\\".$filename;//Windows
$fileNL = $filelocation."/".$filename; //Linux
$this->pdf->Output($fileNL, 'F');
$pdf->Output()
接受第二个参数$dest
,该参数接受一个字符。默认情况下,$dest='I'
在浏览器中打开PDF。
使用F
保存到文件
$pdf->Output('/path/to/file.pdf', 'F')
唯一对我有用的东西:
// save file
$pdf->Output(__DIR__ . '/example_001.pdf', 'F');
exit();
对于谁在存储文件时遇到困难,路径必须一直贯穿到根目录。例如,我的是:
$pdf->Output('/home/username/public_html/app/admin/pdfs/filename.pdf', 'F');
TCPDF用于fopen()
保存文件。Output()
因此,传递给TCPDF函数的任何路径都应该是绝对路径。
如果要保存到相对路径,请使用例如__DIR__
全局常量(请参阅此答案)。
如果你仍然得到
TCPDF错误:无法创建输出文件:myfile.pdf
您可以通过将PDF数据放入变量并将此字符串保存到文件来避免TCPDF的文件保存逻辑:
$pdf_string = $pdf->Output('pseudo.pdf', 'S');
file_put_contents('./mydir/myfile.pdf', $pdf_string);
nick的示例将其保存到您的本地主机。
但是您也可以将其保存到本地驱动器。
如果使用双反斜杠:
$filename= "Invoice.pdf";
$filelocation = "C:\\invoices";
$fileNL = $filelocation."\\".$filename;
$pdf->Output($fileNL,'F');
$pdf->Output($filename,'D'); // you cannot add file location here
PS在Firefox中(可选)工具>选项>常规选项卡>下载>总是问我在哪里保存文件
$pdf->Output( "myfile.pdf", "F");
TCPDF错误:无法创建输出文件:myfile.pdf
在include/tcpdf_static.php
静态函数中大约2435行的文件中,fopenLocal
如果我删除完整的'if语句',它将正常工作。
public static function fopenLocal($filename, $mode) {
/*if (strpos($filename, '://') === false) {
$filename = 'file://'.$filename;
} elseif (strpos($filename, 'file://') !== 0) {
return false;
}*/
return fopen($filename, $mode);
}
您可以尝试;
$this->Output(/path/to/file);
所以对你来说,就像
$this->Output(/kuitit/); //or try ("/kuitit/")
这对我有用,将其保存到temp_pdf
根目录下的子目录dir()中:
$sFilePath = $_SERVER['DOCUMENT_ROOT'] . '//temp_pdf/file.pdf' ;
$pdf->Output( $sFilePath , 'F');
请记住使该目录可写。
本文地址:http://php.askforanswer.com/tcpdfjiangwenjianbaocundaowenjianjia.html
文章标签:php , tcpdf
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!
文章标签:php , tcpdf
版权声明:本文为原创文章,版权归 admin 所有,欢迎分享本文,转载请保留出处!
评论已关闭!