Can anyone help me in displaying PDF document in JSF page in iframe only?
Thanks in advance,
Suresh
Just use the usual way:
If your problem is rather that the PDF is not located in the WebContent
, but rather located somewhere else in disk file system or even in a database, then you basically need a Servlet
which gets an InputStream
of it and writes it to the OutputStream
of the response:
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);
}
This way you can just point to this servlet instead :) E.g.:
You can find a complete example of a similar servlet in this article.
The also works fine in JSF, assuming that you're using JSF 1.2 or newer. In JSF 1.1 or older you have to wrap plain vanilla HTML elements such as
inside a
so that they will be taken into the JSF component tree, otherwise they will be dislocated in the output: