Skip to content
PHP Logo

What are some best practices for printing a PDF file from a browser without displaying the print dialog using PHP?

When printing a PDF file from a browser using PHP, you may want to do so without displaying the print dialog to the user. One way to achieve this is by using a library like TCPDF to generate the PDF file and then use the headers to force the browser to download and print the file automatically without showing the print dialog.

php
require_once('tcpdf/tcpdf.php');

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(0, 10, 'Hello World', 0, 1, 'C');
$pdf->Output('example.pdf', 'D');