Search code examples
internet-explorerpdfpdf-generationpreview

Is there a way to generate a preview of PDF in IE


Is there anyway at all to generate a preview of a PDF in an IE browser?

I know that you could use an iframe in either Chrome or Firefox, and a blob in IE, but they both require their own code, I'm looking for something that will work cross browsers.


Solution

  • Finally found a solution, that generates an in-browser preview window for a PDF file that is supported by all browsers!

    Here's my code (I've put in an input box so that anyone could test any PDF URL):

    <div class="wizard-content">
         <div class="col-md-6">
              <input id="pdfsrc" class="form-control">
              <a id="refresh" href="#" class="btn btn-lg btn-success">Refresh PDF</a>
         </div>
         <div id="myDiv" class="col-md-6">
              <object id="objsrc" data="" type="application/pdf" style="width:100%;height:100%">
                  <embed id="embsrc" src="" type="application/pdf" style="width:100%;height:100%/">
              </object>
         </div>
    </div>
    

    JS:

    $(function() {
        $("#refresh").click(function() {
            var url=document.getElementById('pdfsrc').value;
            $("#objsrc").attr("data", url);
            $("#embsrc").attr("src", url);
            var container = document.getElementById("myDiv");
            var content = container.innerHTML;
            container.innerHTML = content;
        })
    })