I have a dynamically generated PDF using iText in JAVA. Bean Property:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document(PageSize.LETTER);
pdfWriter = PdfWriter.getInstance(document, baos);
//iText code here
ByteArrayInputStream stream = new ByteArrayInputStream(baos.toByteArray());
StreamedContent file = new DefaultStreamedContent(stream,"application/pdf","Sds.pdf");
So, the bean property returns this file variable of StreamedContent type. When I use tag, it works like a charm. But, when I use media object as follows:
<p:media player="pdf" height="500" width="400" value="#{beanName.beanProperty}"></p:media>
I get an alert "File does not begin with %pdf-" and in the console, it says
"org.primefaces.application.PrimeResourceHandler handleResourceRequest
SEVERE: Error in streaming dynamic resource. Expression cannot be null"
I have tried using iframes too but no luck. Basically, I am trying to embed a frame on a webpage in which the dynamic PDF I generate can be loaded automatically as soon as the page loads. Static URLs work but dynamic content doesn't! I have tried various solutions. Primefaces downloadLink works but primefaces media doesn't. BTW, I am trying to do achieve this in IE9. (It doesn't work on Chrome either). I'd really appreciate any help. Thank you!