1

I want to embed pdf file in my website from /var/www/pdf/ directory. I have hosted my webpage at /var/www/html/portal/index.php. I tried following ways

1) using embed

2) using iframe

<iframe src="../../pdf/ebook.pdf" width="900" height="750" frameborder="0" allowfullscreen></iframe>

3) using object

<object data="../../pdf/ebook.pdf#scrollbar=0&toolbar=0&navpanes=0" width="900" height="750" type="application/pdf">
    <p>PDF cannot be displayed</p>
</object> 

None of them working, but if I place the pdf file /var/www/html/pdf/ folder it is working fine.

For my requirement, I cannot keep the file in the web directory because public can access the PDF file directly using URL without login in to my web portal. And Also google also can index my PDF file from public search

Please help me to embed pdf

Thanks in advance

user231410
  • 129
  • 1
  • 15
  • What webserver are you using? – jgmh Jul 05 '17 at 03:20
  • Thank you for your reply. Web Server- Apache and Server OS - CentOS 7 – user231410 Jul 05 '17 at 03:26
  • Does your directory `/var/www/pdf/` count with the required permissions in apache conf? – jgmh Jul 05 '17 at 03:30
  • yes. I can read and write file there – user231410 Jul 05 '17 at 03:34
  • Please check that apache user has the right permissions in that directory (OS level) and in its parent directory (`/var/www/`). Double check the permission scheme in apache conf file. What error do you see? – jgmh Jul 05 '17 at 03:39
  • i re-checked . Apache user has the right permissions. I tested this in the cpanel server also. same issue when pdf directory is outside public-html directory – user231410 Jul 05 '17 at 06:05

2 Answers2

0

You can do it by .htaccess

First : prevent direct access to open pdf file

Refer this questions and answers

Second: prevent Search engine indexing

Refere this

Hope it will work. I try to give this information in comment but it is not displaying properly there.

Parag Soni
  • 713
  • 7
  • 14
0

I found solution using php script

header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=filename.pdf");
@readfile('../../pdf/ebook.pdf');
user231410
  • 129
  • 1
  • 15