pdf下载 html2pdf

发布于 2024-09-26 10:41:11 字数 581 浏览 7 评论 0原文

我正在使用 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; }
?>

i am using html2pdf class to generate pdf. in my problem its generate pdf for the html code but it not give the dialog box option to download that 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; }
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

对你再特殊 2024-10-03 10:41:11

从文档中,方法输出

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

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
     *
墨小沫ゞ 2024-10-03 10:41:11

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

Change this line $html2pdf->Output('pdf_demo.pdf'); to
$html2pdf->Output('pdf_demo.pdf', 'D'); and it will force browser to automatically download the pdf file.

浴红衣 2024-10-03 10:41:11

将 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');

Send PDF to browser with a specific name

$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

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

Write the contents of a PDF file on the server

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

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

$content_PDF = $html2pdf->Output('', 'S');
花桑 2024-10-03 10:41:11

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

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

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

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文