簡體   English   中英

pdf 下載 html2pdf

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM