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

TarikAli's avatar

preview pdf without download

Hello, Now i display a pdf file with iframe no problem but i must prevent the users from download it if they click inspect and get the iframe src link, also cam i display the pdf with stream

0 likes
4 replies
Russelmhardy's avatar

if you use "laravel-dompdf" package you can stream your pdf by that lignes :

$pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML('<h1>Test</h1>');
    return $pdf->stream();

1 like
Snapey's avatar

If the user sees the PDF in their browser then you have already sent it to them.

2 likes
TarikAli's avatar

@Snapey even if stream, the file will be in temp files? so no solution . any user can take the pdf file?

click's avatar

Everything you send to your user via the browser is for them to download, take screenshots or copy in any other way, nothing is private if you show it to your user.

There are workarounds that might make it "harder" to download the file but if someone really wants the PDF of it they will get it. Like for example this approach: https://betterprogramming.pub/how-to-display-pdfs-but-prevent-them-from-downloading-in-react-2e77292ca9a5 or a "pdf viewer" script might make it harder to download the PDF but I can't give you advice on that as I never used it but searching on "pdf viewer html javascript" should give you some options.

I don't know what you are trying to do but might adding a watermark to your PDF help? If they really want they can of course remove the watermark again but it makes it a bit harder.

1 like

Please or to participate in this conversation.