【问题标题】:pdf download html2pdfpdf下载html2pdf
【发布时间】:2011-04-21 15:57:18
【问题描述】:

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

【问题讨论】:

  • 您是说浏览器不提示下载此 pdf 文件选项吗?如果您从 adobe 安装 pdf 插件,这很正常……在我的情况下,浏览器只会在浏览器中“打开”pdf。

标签: php pdf download html2pdf


【解决方案1】:

使用特定名称将 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');

【讨论】:

  • 如何将生成的文件上传到 amazons3 ?
【解决方案2】:

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

【讨论】:

    【解决方案3】:

    来自文档,方法输出

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

    【讨论】:

    • 如何将生成的 pdf 上传到 amazon s3 存储桶?
    【解决方案4】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 2023-03-08
      • 1970-01-01
      • 2012-04-18
      相关资源
      最近更新 更多