@gustavodefreitasmene escreveu:
Boa tarde a todos!
Estou precisando exibir um PDF num p:dialog,
estou usando o p:fileupload pra carregar o arquivo PDF, e o p:media pra exibir,
mas eu não consigo fazer o PDF ser renderizado na tela.Alguém já passou por isso e pode me ajudar?
Ficarei muito grato com qualquer ajudasegue abaixo codigo
XHTML
<td align="left" valign="middle"> <p:media id="imagem" value="#{TrOsoSB.imagem}" width="100%" height="550" player="pdf" /> <p:fileUpload text="Arquivo" label="Procurar..." description="Arquivo" update="imagem" fileUploadListener="#{TrOsoSB.handleFileUpload}" mode="advanced" auto="true" allowTypes="/(\.|\/)(pdf)$/" style="font-size:11px"/> </td> ManagedBean @SessionScoped ... public void handleFileUpload(FileUploadEvent event) throws IOException { imagem = new DefaultStreamedContent(event.getFile().getInputstream(), "application/pdf", event.getFile().getFileName()); byte[] arq = getFileContents(event.getFile().getInputstream()); this.entidade.setOsoPdf(arq); } private byte[] getFileContents(InputStream in) { byte[] bytes = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int read = 0; bytes = new byte[1024]; while ((read = in.read(bytes)) != -1) { bos.write(bytes, 0, read); } bytes = bos.toByteArray(); in.close(); in = null; bos.flush(); bos.close(); bos = null; } catch (IOException e) { System.out.println(e.getMessage()); } return bytes; }
Mensagens: 3
Participantes: 2