Skip to content
Advertisement

pdf download html2pdf

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; }
?>

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement