2

I have launched an HTML5 website. I've integrated a pdf viewer to show a pdf inside browser. However, after uploading files to the host, browser downloads pdf instead of presenting my pdf. Please check Resume section here. Here is the code I'm using:

<!-- SECTION 1.1 - Resume -->
<section class="no-display">
<div class="profile" id="2">
<h2>My<span>Resume</span><br></h2>
<div class="sep1"></div>
<p>
<object data="attach/Resume.pdf" type="application/pdf" width="660" 
height="3710" Content-Disposition: inline; filename=Resume.pdf>
<a href="Resume">Resume.pdf</a>
</object>
</p>

<div class="clearfix"></div>
</div>
</section>
<!-- SECTION 1.1 - Resume -->

Even when you try to open the website (while loading webpage), browser requests to download it!

Update: I checked the header status of my website:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 27522
Connection: keep-alive
Keep-Alive: timeout=15
Date: Sat, 27 May 2017 09:30:38 GMT
Server: Apache
Last-Modified: Sat, 27 May 2017 08:01:38 GMT
ETag: "6b82-5507cdd152130"
Accept-Ranges: bytes

As it is obvious, the content-type is set to text/html. I'm not sure if it is related to this issue or not. If it is, would you pls let me know how to change/edit it ?

Majid
  • 421
  • 6
  • 19
  • All browsers may not have the capability to display PDFs. Consider using [PDF.js](https://mozilla.github.io/pdf.js/). – Abhijit Parida May 27 '17 at 07:21
  • add target="_blank" https://stackoverflow.com/questions/7267242/opening-files-in-browser-instead-of-downloading – Sagar Roy May 27 '17 at 07:45
  • As Abhijit Parida sugested you can use PDF.js: https://github.com/mozilla/pdf.js – Red Devil May 28 '17 at 20:08
  • Does this answer your question? [How do I force files to open in the browser instead of downloading (PDF)?](https://stackoverflow.com/questions/6293893/how-do-i-force-files-to-open-in-the-browser-instead-of-downloading-pdf) – Cornelius Roemer Apr 09 '21 at 13:47

1 Answers1

0

How about use window.open('attach/Resume.pdf');?

<section class="no-display">
    <div class="profile" id="2">
        <h2>My<span>Resume</span><br></h2>
        <div class="sep1"></div>
        <p>
            <object data="attach/Resume.pdf" type="application/pdf" width="660"
                    height="3710" Content-Disposition: inline; filename=Resume.pdf>
                <a href="#"  onclick="window.open('attach/Resume.pdf');">Resume.pdf</a>
            </object>
        </p>

        <div class="clearfix"></div>
    </div>
</section>
Alireza Ahmadi
  • 8,579
  • 5
  • 15
  • 42