简体   繁体   English

pdf 下载 html2pdf

[英]pdf download html2pdf

i am using html2pdf class to generate pdf.我正在使用 html2pdf 类生成 pdf。 in my problem its generate pdf for the html code but it not give the dialog box option to download that pdf.在我的问题中,它为 html 代码生成 pdf,但它没有提供下载该 pdf 的对话框选项。 plz help my cose is following.请帮助我的费用如下。

<?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; }
?>

From the documentation, method Output从文档中,方法输出

    /**
     * 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
     *

Change this line $html2pdf->Output('pdf_demo.pdf');更改这一行$html2pdf->Output('pdf_demo.pdf'); to $html2pdf->Output('pdf_demo.pdf', 'D');$html2pdf->Output('pdf_demo.pdf', 'D'); and it will force browser to automatically download the pdf file.它会强制浏览器自动下载pdf文件。

Send PDF to browser with a specific name使用特定名称将 PDF 发送到浏览器

$html2pdf->Output('document_name.pdf');

$html2pdf->Output('document_name.pdf', false);

$html2pdf->Output('document_name.pdf', '');

$html2pdf->Output('document_name.pdf', 'I');

Force the browser to download the PDF file with a specific name强制浏览器下载指定名称的 PDF 文件

$html2pdf->Output('document_name.pdf', 'D');  

Write the contents of a PDF file on the server在服务器上写入 PDF 文件的内容

Attention, this writing on your server must be used with caution.注意,必须谨慎使用您服务器上的这种文字。 No verification is made on the existence of the file不验证文件是否存在

$html2pdf->Output('directory/filename_xxxx.pdf', 'F');

Retrieve the contents of the PDF and then do whatever you want检索 PDF 的内容,然后做任何你想做的事

$content_PDF = $html2pdf->Output('', true);

$content_PDF = $html2pdf->Output('', 'S');

To offer download from your browser u need add the header for being attachment...要从您的浏览器提供下载,您需要添加标题作为附件...

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

Add the above code at the start of the page and then proceed with the html2pdf conversion..在页面的开头添加上面的代码,然后继续进行html2pdf转换..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM