[英]pdf download html2pdf
我正在使用 html2pdf 类生成 pdf。 在我的问题中,它为 html 代码生成 pdf,但它没有提供下载该 pdf 的对话框选项。 请帮助我的费用如下。
<?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; }
?>
从文档中,方法输出
/**
* 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
*
更改这一行$html2pdf->Output('pdf_demo.pdf');
到$html2pdf->Output('pdf_demo.pdf', 'D');
它会强制浏览器自动下载pdf文件。
使用特定名称将 PDF 发送到浏览器
$html2pdf->Output('document_name.pdf');
$html2pdf->Output('document_name.pdf', false);
$html2pdf->Output('document_name.pdf', '');
$html2pdf->Output('document_name.pdf', 'I');
强制浏览器下载指定名称的 PDF 文件
$html2pdf->Output('document_name.pdf', 'D');
在服务器上写入 PDF 文件的内容
注意,必须谨慎使用您服务器上的这种文字。 不验证文件是否存在
$html2pdf->Output('directory/filename_xxxx.pdf', 'F');
检索 PDF 的内容,然后做任何你想做的事
$content_PDF = $html2pdf->Output('', true);
$content_PDF = $html2pdf->Output('', 'S');
要从您的浏览器提供下载,您需要添加标题作为附件...
header("Content-Disposition: attachment; filename=sample.pdf");
在页面的开头添加上面的代码,然后继续进行html2pdf转换..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.