gpt4 book ai didi

pdf - 如何在 iFrame 的 jsf 页面中显示 pdf 文档

转载 作者:行者123 更新时间:2023-12-04 17:05:36 27 4
gpt4 key购买 nike

任何人都可以帮助我仅在 iframe 中的 JSF 页面中显示 PDF 文档吗?

提前致谢,

苏雷什

最佳答案

只需使用 <iframe>通常的方式:

<iframe src="/path/to/file.pdf"></iframe>

如果您的问题是 PDF 不在 WebContent 中,而是位于磁盘文件系统甚至数据库中的其他位置,那么您基本上需要一个 Servlet得到一个 InputStream并将其写入 OutputStream回应:
response.reset();
response.setContentType("application/pdf");
response.setContentLength(file.length());
response.setHeader("Content-disposition", "inline; filename=\"" + file.getName() + "\"");
BufferedInputStream input = null;
BufferedOutputStream output = null;

try {
input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);

byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int length;
while ((length = input.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
} finally {
close(output);
close(input);
}

这样你就可以只指向这个 servlet :) 例如:
<iframe src="/path/to/servlet/file.pdf"></iframe>

您可以在 this article 中找到类似 servlet 的完整示例。 .
<iframe>在 JSF 中也可以正常工作,假设您使用的是 JSF 1.2 或更新版本。在 JSF 1.1 或更早版本中,您必须包装普通的 HTML 元素,例如 <iframe>里面 <f:verbatim>以便它们将被带入 JSF 组件树,否则它们将在输出中错位:
<f:verbatim><iframe src="/path/to/servlet/file.pdf"></iframe></f:verbatim>

关于pdf - 如何在 iFrame 的 jsf 页面中显示 pdf 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1939778/

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