pdf下载html2pdf

时间:2010-10-06 06:31:45

标签: php pdf download html2pdf

我正在使用html2pdf类生成pdf。在我的问题中它为html代码生成pdf但它没有给出对话框选项来下载该pdf。请帮助我的cose跟随。

<?php
ob_start();
include(dirname(__FILE__).'/res/pdf_demo.php');
$content = ob_get_clean();

// conversion HTML => PDF
require_once(dirname(__FILE__).'/../html2pdf.class.php');
try
{
    $html2pdf = new HTML2PDF('P','A4', 'fr', false, 'ISO-8859-15');
    $html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
    $html2pdf->Output('pdf_demo.pdf'); 
}
catch(HTML2PDF_exception $e) { echo $e; }
?>

4 个答案:

答案 0 :(得分:9)

从文档,方法输出

    /**
     * Send the document to a given destination: string, local file or browser.
     * Dest can be :
     *  I : send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
     *  D : send to the browser and force a file download with the name given by name.
     *  F : save to a local server file with the name given by name.
     *  S : return the document as a string. name is ignored.
     *  FI: equivalent to F + I option
     *  FD: equivalent to F + D option
     *  true  => I
     *  false => S
     *

答案 1 :(得分:7)

将此行$html2pdf->Output('pdf_demo.pdf');更改为 $html2pdf->Output('pdf_demo.pdf', 'D');它会强制浏览器自动下载pdf文件。

答案 2 :(得分:3)

将PDF发送到具有特定名称的浏览器

$ html2pdf-&GT;输出(&#39; document_name.pdf&#39);

$ html2pdf-&gt;输出(&#39; document_name.pdf&#39;,false);

$ html2pdf-&gt;输出(&#39; document_name.pdf&#39;,&#39;&#39;);

$ html2pdf-&gt;输出(&#39; document_name.pdf&#39;,&#39;我&#39;);

强制浏览器下载具有特定名称的PDF文件

$ html2pdf-&gt;输出(&#39; document_name.pdf&#39;,&#39; D&#39;);

在服务器上写下PDF文件的内容

注意,必须谨慎使用服务器上的这篇文章。没有验证文件是否存在

$ html2pdf-&gt;输出(&#39;目录/ filename_xxxx.pdf&#39;,&#39; F&#39;);

检索PDF的内容,然后执行任何操作

$ content_PDF = $ html2pdf-&gt;输出(&#39;&#39;,true);

$ content_PDF = $ html2pdf-&gt;输出(&#39;&#39;,&#39; S&#39;);

答案 3 :(得分:2)

要从您的浏览器下载,您需要添加附件标题...

header("Content-Disposition: attachment; filename=sample.pdf");

在页面开头添加上面的代码,然后继续进行html2pdf转换..

相关问题