Show PDF Files With PrimeFaces

It is pretty easy to preview pdf files with PrimeFaces media component as explained in official page.

If you try this already there are two common problems that may find you.

  • Shows the same file every time
  • Cannot download the file multiple times (if you have an extra download button even the pdf viewer already have one)

To solve the first problem we generate an id for each media file to disable cache [1] .

The main reason of the second problem is that ‘a stream can be read only once’, so simply we have to refill the stream after every download attempt, but how can we understand that download is completed? Fortunately, PrimeFaces gives us some functions to probing download process [2] .

Here is the complete example:

[1] http://stackoverflow.com/questions/18994288/primefaces-update-pdf-media-not-working

[2] http://www.primefaces.org/showcase/ui/file/download.xhtml

Advertisements

2 thoughts on “Show PDF Files With PrimeFaces

  1. Stanley Shi says:

    Good explanation.
    Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: