I have several pdf files saved in ...WebContent/Manuals/filename.pdf
that I am trying to display on my page. I am getting "Failed to Load PDF document" message in Chrome.
My Jsf:
<p:media value="#{reviewBean.manual}" player="pdf" height="600px" width="1000px" />
My @SessionScoped Bean:
public StreamedContent getManual() throws IOException {
String type = "application/pdf"; String path = ""; FacesContext context = FacesContext.getCurrentInstance(); if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { return new DefaultStreamedContent(); } else { path = "C:\\.....\\WebContent\\Manuals\\filename.pdf"; InputStream is = new ByteArrayInputStream(path.getBytes()); return new DefaultStreamedContent(is, type); } }
There is additional logic that i have left out for clarity which decides which pdf is displayed.
I have also tried the file path of /Manuals/filename.pdf
as path
I tried following the below example:
How to bind dynamic content using <p:media>?
In my case I do not need to retrieve a value using <f:param
Is my file path incorrect to display the image? Or am I building the Stream incorrectly? Any guidance is much appreciated.