0

I have backend link which I click (or pass it to tag) it starts downloading. How can I display i? I dont want users to be able to download it, just want to display it in my react component.

I already tried something like this:

   async function createFile(url) {
    let response = await fetch(url);
    let data = await response.blob();
    let metadata = {
      type: "application/pdf",
    };
    let file = new File([data], "12121.pdf", metadata);
    return file;
  }

  const [file, setFile] = useState();

  useEffect(() => {
    if (pdf) {
      setFile(createFile(pdf));
    }
  }, [pdf])

and then i tried to display it by

 <embed src={file} width="800px" height="2100px" />

but it doesnt seems to work..

rm98
  • 1
  • download or view both are same actions in term of file. If you even able to only view the pdf file obviously through browser or embedded tool then user can download that as well. so logically both things are the same. he can't just view. first the file has to be downloaded in order to view. – Muhammad Atif Akram Dec 24 '21 at 09:19
  • Consider displaying the document to the user in a viewer component that will display the PDF in the user’s browser when clicking the link. For example, the LEADTOOLS HTML5 Document Viewer can be used with ReactJS to accomplish this. You can find a simple tutorial for this [here](https://www.leadtools.com/help/sdk/v22/tutorials/html5-reactjs-display-files-in-the-document-viewer.html). (Disclaimer: I am an employee of the vendor) – Hussam Barouqa Jan 06 '22 at 16:19

0 Answers0