上传前预览 PDF/图像文件 [英] Preview PDF/Image file before upload

查看:44
本文介绍了上传前预览 PDF/图像文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何,pdf/图像文件可以在上传前自动预览/显示在 iframe 中,而无需单击预览按钮吗?

function PreviewImage() {pdffile=document.getElementById("uploadPDF").files[0];pdffile_url=URL.createObjectURL(pdffile);$('#viewer').attr('src',pdffile_url);}

<input id="uploadPDF" type="file" name="file"/>&nbsp;<input type="button" value="Preview" onclick="PreviewImage();"/><div style="clear:both"><iframe id="viewer" frameborder="0" scrolling="no" width="300" height="200"></iframe>

<button type="submit" name="submit" class="btn btn-success btn-sm"><i class="fa fa-dot-circle-o"></i>添加</button>&emsp;</表单><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

解决方案

您可以从此链接使用像这样的 javascript pdf 库(我正在使用 pdf.js):https://mozilla.github.io/pdf.js/examples/index.html#interactive-examples

//通过 



        
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆