Bom dia Pessoal.
Pesquisando aqui no forum eu achei uns tópicos resolvidos que mostravam como exibir
um documento pdf usando JSF, que segue abaixo:
public void exibir(){
HttpServletResponse response=(HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
ServletContext serveletContext=(ServletContext) FacesContext.getCurrentInstance().getExternalContex().getContext();
try {
File file=new File("C:\\teste.pdf");
byte[] b = fileToByte(file);
HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext ().getResponse();
res.setContentType("application/pdf");
res.setHeader("Content-disposition", "attachment;filename="+file.getName());
res.getOutputStream().write(b);
res.getCharacterEncoding();
FacesContext.getCurrentInstance().responseComplete();
} catch (Exception e) {
e.printStackTrace();
}
}
public static byte[] fileToByte(File imagem) throws Exception {
FileInputStream fis = new FileInputStream(imagem);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int bytesRead = 0;
while ((bytesRead = fis.read(buffer, 0, 8192)) != -1) {
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
}
Tanto o mozila quanto o IE estão com suporte a arquivos pdf, porque quando eu redireciono a página para .pdf
são exibidos normalmente.
Eu agradeço qualquer sugestão que vcs possam dar.