1

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!

A M
  • 448
  • 5
  • 11
  • 1
    Is your bean `@ViewScoped`? That tends to cause to cause problems as the Primefaces resource servlet tries to stream the content on a separate request in which the `UIViewRoot` is not available and therefore the view scope isn't either. Try session or request scope. – rdcrng Aug 15 '13 at 18:27
  • Hi Balus, I can't understand what you implemented in the class MediaService. I see you are using some find(long something) method there. Thanks! – A M Aug 15 '13 at 23:05
  • rdcrng, Thanks for replying. I've tried SessionScoped and it works on Google Chrome. I want to make this work on IE as our webapp is supposed to work on IE only. – A M Aug 16 '13 at 16:13

0 Answers0