如何在smarty中创建从fpdf创建的pdf时下载pdf

时间:2013-01-07 11:42:14

标签: php pdf header smarty fpdf

嗨我需要在smarty中创建一个pdf的下载行,我已经从fpdf制作了,在fire bug中显示了pdf文件,但是我可以在smarty中创建一个下载链接,我的代码如下所示。

$content = $this->view->fetch($pdf->Output());
 $router->disableRender();
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-disposition: attachment; filename="doc.pdf"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');

    ob_clean();
    flush();

    readfile(doc.pdf);
    die;

请帮助我thax adv ........

1 个答案:

答案 0 :(得分:0)

在代码的顶部,您说的是

$content = $this->view->fetch($pdf->Output());
 $router->disableRender();

然后在底部,你说

ob_clean();
flush();

readfile(doc.pdf);
die;

现在,除了这应该导致PHP警告 - 未定义的常量doc.pdf,假设一个字符串等 - 这个代码不能做你认为它做的事情。在任何时候你都不会将PDF内容写入磁盘,那么你如何期望从磁盘读取它会起作用呢?

您需要在发出文件之前将$content写入文件,或者只需要echo $content

您是否尝试对此进行排查?

相关问题