문제

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; }
?>
도움이 되었습니까?

해결책

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

다른 팁

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
     *

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.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top