Monday, November 15, 2010

Printing in ADF, the <af:showPrintablePageBehavior> and showing the browser print dialog

ADF comes with a couple of rather easy to implement options for printing and rendering printable pages. The most obvious one is the <af:showPrintablePageBehavior/>. As the document describes, this renders the page without any command components, and as such will look better on paper. The big drawback however is that this is just the same page rendered differently. What if the actual behavior you need is to open the print dialog of the browser ?
There is a javascript function in the ADF client side API hat you can use to do exactly this. The function is simply self.print() and it opens up the browser's print dialog.

To use the function, just drop an tag into a command button like so :

The corresponding code in your jspx/jsff would be :
<af:commandToolbarButton text="show print dialog" id="ctb2">
    <af:clientListener method="self.print" type="action"/>

And of course you can use the self.print()function insde your own custom java script that ou embed with the af:resource tag. The downside of this approach is that what you see is what you get.
The page is sent to the printer as is, Its not specifically made "printer friendly" by removing CSS and command buttons that the <af:showPrintablePageBehavior/> does .

The <af:showPrintablePageBehavior/> approach would be :
<af:commandToolbarButton text="show printable page" id="ctb1">


  1. Thank you so much for this post, I was doing the printable version the hard way. Just added your blog to the favorite list, I'll spend some time reading all your posts to see what else I can learn!

    1. This is awesome that printing can be made that much easier! Being a college student I always have lots of things to print out; any time that can be saved is a huge bonus. Great post on how to set-up quick printing options.

  2. Thanks for the kind words Markos. Glad that you found something here useful !

    I have more content coming up in ADF and in WebCenter. If you'd like me to post examples of anything you'd like to see, please post comment, I'll try to give it a shot (I'm no expert by any means) .

  3. Thank you so much...this made my work very easy...I was fedup with printableBehaviour and ur blog helped me a lot..I love it and will definitely read all the remaining posts..U are really helpful..thanq you frend

  4. Thanks for the kind words Ragini. I've moved on to blogging here now :

    You will find a lot of useful ADF and WebCenter tips and trick there.

  5. Bagus banget nih artikel nya
    kunjungi juga blog kami ada artikel menarik tiap hari nya
    Jangan lupa main di indomonopoly