How to download a PDF that is in C:

Asked

Viewed 124 times

0

With the code below I can download a JPG, but with PDF does not work. I tried to change the last line for that, but it didn’t work either.

file = new DefaultStreamedContent(stream, "application/pdf", fileName);

<p:commandButton value="Download do Edital" ajax="false"  >
     <p:fileDownload value="#{fileUploadBean.file}" />
</p:commandButton>

private StreamedContent file;

    public void setFile(StreamedContent file) {
            this.file = file;
        }

    public StreamedContent getFile() throws FileNotFoundException {
        String caminho = "c:/tmp/iri.jpg";
        String arquivo = "iri.jpg";
        FileInputStream stream = new FileInputStream(caminho);      
        file = new DefaultStreamedContent(stream, caminho, arquivo);  

      return file;
    }
  • 1

    See if it can help you, http://stackoverflow.com/questions/20265740/how-to-download-a-pdf-from-a-given-url-in-java

  • 1

    Does it not work for what reason? There is some error?

1 answer

1


 public StreamedContent getFile() throws FileNotFoundException {

    String arquivo = "iri.jpg";

    String caminho = "C:\\tmp\\"+arquivo;

    FileInputStream stream = new FileInputStream(caminho);      
    file = new DefaultStreamedContent(stream, caminho, arquivo);  

  return file;
}
  • 2

    http://answall.com/help/how-to-answer

  • See if it works !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.