java - 使用 Primeface DefaultStreamedContent 查看中文内容 PDF 时出现 InvalidPDFException
问题描述
使用Primefaces 6.0和 JAVA 1.8
使用下面的代码使用 . 查看 PDF 文档DefaultStreamedContent
。
<pe:documentViewer locale="en" height="600" value="#{documentMBean.pdfFile}" id="pdfDocViewer" >
下面的代码将 Stream 作为 pdfFile 获取。
byte[] documentData = null;
setPdfFile(new DefaultStreamedContent());
documentData =//Getting the byte array from DB
getPdfFile().setStream(new ByteArrayInputStream(documentData));
getPdfFile().setContentType("application/pdf");
getPdfFile().setContentEncoding("UTF-8");
当我上传并存储包含中文字符的 PDF 文件在 PDF 查看器中低于异常时。
PDF.js v1.0.21 (build: f954cde) 消息:InvalidPDFException
注意:纯文本 PDF,其内容英文字符工作正常,能够查看 PDF。
我尝试设置不同的字符编码,例如 UTF-8、UTF-16
请帮助我如何解决上述异常。在哪里可以找到 PDF.js 进行进一步分析?
解决方案
推荐阅读
- python - 在 python 的类中初始化实例变量的最佳实践是什么?
- regex - 用于连接破折号的 Bash 脚本
- powershell - Powershell - 扫描 DC 寻找新服务器 + 如果特定服务正在其上运行
- android - Fragments - 指定的孩子已经有一个父母。在片段导航时,您必须首先在孩子的父母上调用 removeView()
- android - 如何在 Kotlin 中模拟 getSting 资源
- c++ - unordered_set 可以为节点和桶列表使用不同的分配器吗?
- javascript - 在 React 中使用 Router 将数据从一个页面传递到另一个页面
- android - 文本对齐 - Android GravityFlags.Right 切断每行的第一个字符
- sql-server - SSIS 包 - 自动每月刷新数据
- unit-testing - PHP单元测试模拟成员变量依赖