質問

HTML2PDFクラスを使用してPDFを生成しています。私の問題では、HTMLコードのPDFを生成しますが、ダイアログボックスオプションを提供して、そのPDFをダウンロードしません。 PLZは私のCOSEがフォローしているのを助けます。

<?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; }
?>
役に立ちましたか?

解決

ブラウザからダウンロードを提供するには、添付ファイルになるためにヘッダーを追加する必要があります...

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

ページの開始時に上記のコードを追加し、HTML2PDF変換を続行します。

他のヒント

ドキュメントから、メソッド出力

    /**
     * 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');

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top