首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pdf下载html2pdf

pdf下载html2pdf
EN

Stack Overflow用户
提问于 2010-10-06 14:31:45
回答 4查看 21.9K关注 0票数 2

我正在使用html2pdf类来生成pdf。在我的问题中,它为html代码生成pdf,但它没有给对话框提供下载该pdf的选项。请帮我的忙,下面是我的建议。

代码语言:javascript
复制
<?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; }
?>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2010-10-06 14:44:20

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

代码语言:javascript
复制
header("Content-Disposition: attachment; filename=sample.pdf");

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

票数 2
EN

Stack Overflow用户

发布于 2013-05-20 17:03:07

从文档中,方法输出

代码语言:javascript
复制
    /**
     * 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
     *
票数 9
EN

Stack Overflow用户

发布于 2015-06-25 12:37:04

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

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3870006

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档