首页 > 解决方案 > 使用 Primeface DefaultStreamedContent 查看中文内容 PDF 时出现 InvalidPDFException

问题描述

使用Primefaces 6.0JAVA 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 进行进一步分析?

标签: javapdfprimefacesprimefaces-extensions

解决方案


推荐阅读