<" />
<" />
<"/>

PDFObject using Input Type File

431 views Asked by At

I can load the pdf file from the server using this code

  <input type="file" id="imgPreview">
    <div class="container" >
                    <div id="viewpdf"></div>
                </div>
                <script>
                
                    var viewer = $("#viewpdf");
                    PDFObject.embed("{{url('public/uploads/LANDMARK.pdf')}}", viewer);
                </script>

but what I'm trying to do is to load the pdf file attached from the imgPreview input file type

1

There are 1 answers

0
Amit Saini On

Use like this:

$( document ).ready(function() {
   $( "#imgPreview" ).change(function() {
      var inputFile = this.files[0];
      var url=window.URL.createObjectURL(inputFile);
      var viewer = $("#viewpdf");
      PDFObject.embed(url, viewer);
   });
});