How do i open a local pdf file in the browser with the download option

770 Views Asked by At

I want to open a PDF file in the browser but instead of opening, it is downloading. I do not want to change the default settings of the browser.

If there any PDF viewer package which is easy to use, please refer. I tried like this

first import the pdf

import Pdf from "../../../assets/pdf/abc.pdf";

then tried to open it like this

<a href={Pdf} target="\_blank" className="btn"\>Learn More</a>

But it is downloading the file. But I want to open it.

2

There are 2 best solutions below

0
On

As a user you have full control, as a server you can only request the user follows your desires, but they do not have to.

A PDF application/pdf mime file is a potential source of exploit so just like a user can change settings to block adverts or images they can also block unsolicited display of a PDF.

The browsing client may choose to download and view or download only or do not download it is the same in Mozilla or Chromium, just different plugins.

enter image description here

enter image description here

0
On

If you are using Chrome browser, select the three vertical dots in the upper-right corner. Choose Settings > Advanced > Privacy and security. Select Site Settings > PDF documents. Use the toggle switch next to Download PDF files instead of automatically opening them in Chrome to turn the feature on and off.