-1

when i select a pdf file from my pc and click on submit button. Default embeded pdf should be replaced by new pdf that i uploaded. By using only javascript

<form action="" id="myform" method="POST" enctype="multipart/form-data">


                <input type="file" name="uploadfile" placeholder="Upload file" id="">

                <button id="submitfile" class="filesubmitbutton">Submit</button>
            </form>

                <embed id="myEmbed" src="../NISHANTKUMAR.pdf" type="application/pdf" width="100%" height="600px">

can uderstand how to do it i tried to change src of embed using javascript But i cant get actual path of file in input

1 Answers1

0

For security reasons, it is not possible to access the real file path programmatically on the user machine. You only have two options

  • Upload the pdf file to your server and update the embed src accordingly
  • Read the pdf content (yes, while you cannot know the file path, you can read the file content) and render it using an external JS PDF viewer, (e.g. how to open a local PDF in PDFJS using file input?)
Quang Quach
  • 168
  • 1
  • 2
  • 7