Page 1 of 1

media PDF document not displayed

Posted: 24 Oct 2012, 13:37
by chrishj
I am creating PDF documents in the web layer using Itext 2.1.7.

I can down the generated PDF using <p:filedownload ... but I really want to display the PDF document in the middle of a <p:dialog

If I use media command shown below I get blank area when using crome and firefox browser crashes.
In the Glassfish log it notes that mimetype is not known.

Code: Select all

<p:media value="#{arDoc.invoicePDF}" player="pdf"/>
In showcase there is a blank area where the PDF document shoul be rendered.

Is it necessary to configure mimetypes in glassfish to use <p:media ?


Thank

Chris

Re: media PDF document not displayed

Posted: 25 Oct 2012, 06:57
by smithh032772
I searched the forum (via forum search in upper right corner of this page) for the following:

pdf

scrolled down the list of results, and found the forum topic below:

viewtopic.php?f=3&t=25150&p=79877&hilit=pdf#p79835

Why did I know about this forum topic, because I like to scan forum topics almost daily, just to see what other people are talking about, and many many times, I am inspired to add some feature to my JSF/PrimeFaces app after reading/scanning forum topics here.

You can learn a lot this way, and then there will be 'almost' no need to ever ask a question (that was already asked and/or answered, already). :)

Re: media PDF document not displayed

Posted: 25 Oct 2012, 09:59
by chrishj
The previous thread recommends using p:media. I am attempting to use p:media.

Additionally the showcase example does not work correctly.

If p: media cannot handle pdf documents then perhaps the documentation should be amended to remove player="pdf" as a valid usage.

Searching on glassfish I have found that some article suggesting web.xml should be updated for the mime type and others stating that it is built into glasfish.

Code: Select all

<mime-mapping>
     <extension>pdf</extension>
     <mime-type>application/pdf</mime-type>
</mime-mapping>

If you have media working what changes have you needed to make?

The bean method that creates the pdf is as below. Is there an error in this:

Code: Select all

public StreamedContent getInvoicePDF ()throws IOException {
 logger.log(INFO, "getInvoicePDF called");
 String fname = "Invoice-"+this.invoice.getInvoiceNumber()+".pdf";
 
  try{
  ByteArrayOutputStream baos = this.invoicePdfStream();
  
  if(baos == null){
   throw new BacException("pdf not set");
  }
 
 byte[] outputFile = baos.toByteArray();
 invoice.setInvoicePdf(outputFile);
 logger.log(INFO, "outputFile {0}", outputFile.length);
 ByteArrayInputStream bais = new ByteArrayInputStream(invoice.getInvoicePdf());
 
 invoiceMedia = new DefaultStreamedContent(bais, "application/pdf",fname);
 logger.log(INFO, "invoiceMedia {0}", invoiceMedia);
 baos.flush();
 baos.close();
 bais.close();
 return invoiceMedia;
                
 }catch(DocumentException ex){
  String msg = errorForKey("slInvNoInvPdf");
  GenUtil.addErrorMessage(msg);
  throw new BacException("Could not create invoice pdf document reason: "+ex.getLocalizedMessage());
 }
 
}

Thanks

Re: media PDF document not displayed

Posted: 25 Oct 2012, 16:05
by smithh032772
andyba wrote:I really recommend using http://pdfobject.com/ in particular their generator for scriptless markup.
Or you can use a p:media tag....
Maybe andyba might see this and respond to your question(s).

Re: media PDF document not displayed

Posted: 26 Oct 2012, 00:56
by chrishj
I have tried to set the mime-type in web.xml this does not help the issue so it is not a glassfish problem.

Code: Select all

<mime-mapping>
     <extension>pdf</extension>
     <mime-type>application/pdf</mime-type>
    </mime-mapping>

media attribute player="pdf" seems no longer to be supported

Posted: 02 Nov 2012, 22:27
by witcradg
I'm also trying to use pdf with DefaultStreamedContent and the media tag using primefaces 3.4.1

pdfStream = new DefaultStreamedContent(is, "application/pdf");

<p:media value="#{reportBackerBean.pdfStream}" width="100%" height="300px">

Since the default is based on the file extension (see http://cagataycivici.wordpress.com/2010 ... rimefaces/),
I can understand if it is not able to detect what player to use. However, player="pdf" seems no longer to be supported.
The attributes section of the media tag documentation indicates
attribute: player, possible values are "quicktime","windows","flash","real".
(http://www.primefaces.org/documentation.html version 3.3)

Based on examples I saw online, I saw tried this with the player="pdf" attribute:
<p:media value="#{reportBackerBean.pdfStream}" player="pdf" width="100%" height="300px">
but I see the following error:
"pdf is not a valid media player type"

Dropping this line into my getPdfStream method shows that there is no player "pdf"
Map<String, MediaPlayer> mp = MediaPlayerFactory.getPlayers();
mp =
[0] HashMap$Entry "real => org.primefaces.component.media.player.RealPlayer@3acd811"
[1] HashMap$Entry "flash => org.primefaces.component.media.player.FlashPlayer@489d45f9"
[2] HashMap$Entry "windows => org.primefaces.component.media.player.WindowsPlayer@4d5d03ad"
[3] HashMap$Entry "quicktime => org.primefaces.component.media.player.QuickTimePlayer@159c7a89"

This matches the source code I found at http://grepcode.com/file/repository.pri ... ctory.java
getPlayers() {
if(players == null) {
players = new HashMap<String, MediaPlayer>();
players.put(MediaPlayer.QUICKTIME, new QuickTimePlayer());
players.put(MediaPlayer.FLASH, new FlashPlayer());
players.put(MediaPlayer.WINDOWS, new WindowsPlayer());
players.put(MediaPlayer.REAL, new RealPlayer());
}

I found source for a different version of this MediaPlayerFactory.getPlayers() which included the line but this does not currently seem to be available in primefaces 3.4.1.
players.put(MediaPlayer.PDF, new PDFPlayer());
http://code.google.com/p/primefaces/sou ... ava?r=7840

Has anyone been able to get the media tag to work for pdf display using DefaultStreamedContent?


primefaces 3.4.1
glassfish 3.1.2
firefox 16.0.2

Re: media PDF document not displayed

Posted: 03 Nov 2012, 16:34
by smithh032772
@witcradg, very interesting post/response, and thanks for communicating your findings/research and what you learned.

Since PDF is no longer supported with p:media, then use another approach/workaround instead of waiting or hoping for this issue to be fixed/resolved.

PrimeFaces LightBox component should be sufficient to display your PDF in an iFrame. As the showcase example for Lightbox demonstrates, after enduser is finished viewing the document, then click somewhere/anywhere on parent page, and the lightbox/iframe closes or is hidden.

This is almost motivating me to display my PDF content/reports via p:lightBox, but I'm quite satisfied using p:fileDownload to display PDF content/reports in a separate browser tab/window, since the PDF files span entire width of the viewport (or computer monitor), and the same PDF files are printed to printers, attached to emails, or faxed to customers/employees.

Endusers are 'trained' to close browser tab/window that allows them to 'view' the PDF prior to printing emailing or faxing the PDF.

Re: media PDF document not displayed

Posted: 05 Nov 2012, 14:43
by chrishj
It looks as though an issue has been created to display PDFs inline. Issue number 3533
http://code.google.com/p/primefaces/iss ... il?id=3533

This does not appear not work correctly.