Rectangle 27 0

Show a PDF files in users browser via PHPPerl?


$url ="https://yourFile.pdf";
    $content = file_get_contents($url);

    header('Content-Type: application/pdf');
    header('Content-Length: ' . strlen($content));
    header('Content-Disposition: inline; filename="YourFileName.pdf"');
    header('Cache-Control: private, max-age=0, must-revalidate');
    header('Pragma: public');
    ini_set('zlib.output_compression','0');

    die($content);
Content-Disposition: attachment
Content-Disposition: inline

Tested and works fine. If you want the file to download instead, replace

with

Note
Rectangle 27 0

Show a PDF files in users browser via PHPPerl?


Besides, it would not be theft, because the original is still there.

Here is a pure Java PDF renderer if you could server it pdf-renderer.dev.java.net

This is the only really safe way to prevent the theft of the original document.

You could modify a PDF renderer such as xpdf or evince to render into a graphics image on your server, and then deliver the image to the user. This is how Google's quick view of PDF files works, they render it locally, then deliver images to the user. No downloaded PDF file, and the source is pretty well obscured. :)

Note
Rectangle 27 0

Show a PDF files in users browser via PHPPerl?


@dimassony maybe show the full code

Also remember that this will also be affected by browser settings - some browsers may be configured to always download PDF files or open them in a different application (e.g. Adobe Reader)

I assume you want the PDF to display in the browser, rather than forcing a download. If that is the case, try setting the Content-Disposition header with a value of inline.

Yes. But when I'm trying your suggestion, I get an error says "File does not begin with '%PDF-'". I use 'Content-Disposition: inline; filename="the.pdf"'. Do I made a mistake?

good to hear, and great to know the solution! It'd be good if you could post the final code showing which headers you're sending, for anyone else who comes across this question.

sounds like it's not a valid PDF file?

Note
Rectangle 27 0

Show a PDF files in users browser via PHPPerl?


The safest way to have a PDF display instead of download seems to be embedding it using an object or iframe element. There are also 3rd party solutions like Google's PDF viewer.

There's also DoPDF, a Java based In-browser PDF viewer. I can't speak to its quality but it looks interesting.

Note
Rectangle 27 0

Show a PDF files in users browser via PHPPerl?


You can also use fpdf class available at: http://www.fpdf.org. It gives options for both outputting to a file and displaying on browser.

Note