Preview .doc/.docx/.pdf files before uploading to server

前端 未结 8 698
抹茶落季
抹茶落季 2021-02-02 11:01

I\'m using HTML5 File API to get some document(.doc/.docx/.pdf) uploaded. And I want to show that document preview before uploading it to server. Is there any way to do such thi

相关标签:
8条回答
  • 2021-02-02 11:47

    The File API will allow you to read the data from the file, but then you have the trouble of parsing it and rendering it. Mozilla have released a JavaScript PDF viewer, but I'm not aware of anything for MS Office files.

    0 讨论(0)
  • 2021-02-02 11:50

    I have tried to create little example and that would display PDF Preview before uploading PDF file.

    <!DOCTYPE html>
      <html lang="en">
        <head>
            <title>JavaScript PDF Viewer Demo</title>
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
            <script type="text/javascript">
                function PreviewImage() {
                    pdffile=document.getElementById("uploadPDF").files[0];
                    pdffile_url=URL.createObjectURL(pdffile);
                    $('#viewer').attr('src',pdffile_url);
                }
            </script>
        </head>
        <body>
            <input id="uploadPDF" type="file" name="myPDF"/>&nbsp;
            <input type="button" value="Preview" onclick="PreviewImage();" />
    
            <div style="clear:both">
               <iframe id="viewer" frameborder="0" scrolling="no" width="400" height="600"></iframe>
            </div>
        </body> 
    </html>
    
    0 讨论(0)
提交回复
热议问题