0

I want to display some pdf file on my website, but I do not want people to download the file. like scribd.com that displays the document. anyone can help me?

wahdan
  • 7
  • 3

1 Answers1

1

If you want to make sure your user cannot download the original PDF file you will have to convert it to something else before.

Scribd converts the PDF to HTML (with one image in the background that contains all non-text objects). I am not aware of any PDF to HTML parsers, so you would have to write your own. Due to the nature of PDF files, this will unfortunately not be easy (see this question for some more details: Convert PDF to HTML in PHP?)

If you are fine with relying on some external web service, you might try this: https://cloudconvert.org/pdf-to-html

As an alternative to parsing the PDF to HTML, you could also just output it as an image. This is much easier to achieve but also not very nice in terms of user experience. If you chose this method, the easiest way would be to use ImageMagick and Ghostscript (see https://stackoverflow.com/a/467805):

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo $im;
Community
  • 1
  • 1
baltpeter
  • 505
  • 1
  • 6
  • 15