首页 > 解决方案 > 对象 PDF 查看器无法在 chrome 中呈现超过 2.0 MB 的大文件

问题描述

抱歉,如果之前可能有人问过这个问题,但我试图在上传之前显示 pdf 文档的预览,并且仅适用于小于 1Mb 数据的 pdf。上面的任何数据似乎都没有显示在我的浏览器中。我正在使用铬。这是我的 XHTML 代码,它适用于小于 1MB 的 pdf 文件。

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>

        <script type="text/javascript">
            //<![CDATA[ 
         

          
            function renderPDF(input)
            {

                if (input.files && input.files[0])
                {
                    var reader = new FileReader();
                    reader.onload = function (e)
                    {
                  
                        $('#p_viewer').attr('src', e.target.result);
                    };
                    reader.readAsDataURL(input.files[0]);
                }

            }
            
    
            //]]> 
        </script>
    </h:head>
    <h:body>
        <div class="row">
            <div class="col-md-4">
                <h:form id="uploader_form" enctype="multipart/form-data">

                    <h:inputFile value="#{up.file}" onchange="renderPDF(this)" />

                </h:form>
            </div>
            <div class="col-md-8">
                <p:outputPanel id="out">
                    <iframe frameborder="0"   height="600"  width="100%" id="p_viewer" type="application/pdf">
                        
                    </iframe>
                  
                </p:outputPanel>

            </div>
        </div>
    </h:body>
</html>

或者在单击上传提交按钮之前是否有另一种方法可以在 JSF 中显示 pdf 文档?

标签: javascripthtmljsf

解决方案


推荐阅读