gpt4 book ai didi

java - 尽管原始文件有效,但从服务器下载的 PDF 无效

转载 作者:行者123 更新时间:2023-12-01 16:44:41 25 4
gpt4 key购买 nike

我正在使用 Omnifaces 创建 pdf 下载按钮并从服务器获取 pdf。下载的 pdf 有空白页,使用 pdf validator 后我收到此错误:

Validating file "manual(6).pdf" for conformance level pdf1.7

The 'xref' keyword was not found or the xref table is malformed.

The file trailer dictionary is missing or invalid.

The "Length" key of the stream object is wrong.

Error in Flate stream: data error.

The "Length" key of the stream object is wrong.

The document does not conform to the requested standard.

The file format (header, trailer, objects, xref, streams) is corrupted.

The document does not conform to the PDF 1.7 standard.

Done.

我的代码适用于其他 pdf 文件。

这是我的代码:

@ManagedBean
public class FileDownloadView {

private static final String FILENAME = "manual.pdf";

public void download() throws IOException {
Resource resource = new ClassPathResource(FILENAME);
File file = resource.getFile();
Faces.sendFile(file, true);
}

}

和 xhtml:

<h:form>
<p:commandButton action="#{fileDownloadView.download}" value="download" ajax="false">
</p:commandButton>
</h:form>

pdf validator 扫描的原始 pdf 文件没有返回任何错误。下载后的pdf返回上述错误。

请帮忙,先谢谢了!

最佳答案

your comment in a followup question表明 maven 在构建 .war 存档期间损坏了您的 PDF,我建议您必须在构建 POM.xml 中的 PDF 文件期间禁用 maven 资源过滤:

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>*.pdf</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>*.pdf</include>
</includes>
</resource>
</resources>

关于java - 尽管原始文件有效,但从服务器下载的 PDF 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54417547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com