hello
hello

Reputation: 21

how to open print window after creating pdf in dompdf?

i converted my html to Pdf using dompdf and i want to print it. My problem is how to open my pdf file in print window instead of opening the download dialog?

include('dompdf/dompdf_config.inc.php');

$savein = 'pdfdirectory/';  

$html = " my htmlcode here " 

$dompdf = new DOMPDF();
$dompdf->load_html($html);            
$dompdf->render();      

$pdf = $dompdf->output();             
file_put_contents(($savein.'file.pdf'), $pdf);           

$dompdf->stream('file.pdf'); 

Upvotes: 2

Views: 6683

Answers (1)

BrianS
BrianS

Reputation: 13924

You can't force the user to open the file in their browser, but you can specify options for the stream() method that hint to the browser whether or not to download the file. The default is to tell the browser that the file is an "attachment" which usually translates to a download. But if you modify the last line of your code as follows most browsers should display the PDF in the browser:

$dompdf->stream( 'file.pdf' , array( 'Attachment'=>0 ) );

Upvotes: 5

Related Questions