Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

damann8479's avatar

Print DOMPDF

hello, in my laravel project i use dompdf. all works fine. when i click the button i see the pdf view. and in the view i can click print. . i want after button click immediately automatically the pdf print without preview.

i hope someone can help me

0 likes
4 replies
hupp's avatar

@damann8479 add this line of javascript on the click button function. it will open the print dialog instantly.

window.print();
Pippo's avatar

@damann8479 you have to hack a bit with JS. e.g. instead sending the pdf directly to the browser you can do something like this:

const  file = await fetch(yourPDFUrl).then(resp => resp.blob());
const url = URL.createObjectURL(file);
const winPdf = window.open(url);
winPdf.print();

but you always have to activate print button of the browser

damann8479's avatar

@Pippo Thanks for your answer. But I need a way that I don't always have to activate the print button in the browser. I need a way that I can click on my button in my application and the label will be printed. without another click in the browser

Pippo's avatar

@damann8479 I think it's almost impossible, at least without some plugin installed on the browser

Please or to participate in this conversation.