SOTFUL
Links
  • Home
  • About Us
    • Oracle APEX Experts
  • Software
    • Evermenu >
      • Your Ad in Evermenu
      • Privacy Policy
  • Oracle APEX Services
    • Rates for Clients
    • Rates for Vendors Request
    • Development Service Request
    • Sandro Ferreira's Resume
  • Blogs
    • Sandro's APEX Blog
    • Sandro's ClickUp Blog
  • Career
  • Contact Us

Quickest Print Friendly in Oracle APEX

3/20/2018

15 Comments

 

Scenario

Recently I was asked in two different projects to implement a simple way to print the current APEX page without requiring any client software or plugin, and also preserving the main appearance of the APEX page.
​
There are several more sophisticated ways to implement a Print Friendly in Oracle APEX. This is the quickest solution I could think of, following the requirements mentioned above.
​

Solution

The solution basically hides all page components that should not be printed and invokes the browser print, and then the user can choose to print or save the pdf file. Then all the page components that were hidden before are shown back to the user.

The implementation consist of Dynamic Actions to do the Hide, the window.print() JavaScript command to invoke the browser print and then Dynamic Actions to show the components back. An even quicker implementation is to place all the necessary JavaScript code in a single Dynamic Action (Click Print Button) that will do the Hides, Print and Shows.

​Below are the steps to implement this solution.

Implementation

Classic Reports

After creating your APEX Page with a Classic Report, create a button and name it Print. ​
Picture

​
For the button to look like this
Picture
you have to define the Icon CSS Class as fa-print and change the Button Template to Text with Icon.


​
Then you create a Dynamic Action in the Print Button, and define the When section to be Click - Button - Print.
Picture


​Then for the True you choose 
Execute JavaScript Code.
Picture

and in Settings - Code, you paste the following code below:
Code Editor

    
If the Report data is too wide you can placing the following CSS in the Page Properties so that the Print is in Landscape format
Picture
That is it. You are now ready to run the page, click on the Print button and then you will have the behavior shown below.
Picture
​
​Following up in this article, we have this same solution implemented in pages with other types of Oracle APEX components. All the examples in this article are developed in the demo SOTFUL - APEX Examples application. Link and credentials are available below.


​

Interactive Report

The solution above can also work on an Interactive Report with some adjustments. We need the code below, similar to the one above, plus one additional step.

    

​Additional step:

In your Interactive Report click on Attributes, then on Heading change
Fixed To     None
Picture

​Now let's run the page. Click on the Print button and then you will have the behavior shown below.
Picture


​

Form

After creating your APEX Page with a Form create a button and name it Print.

​Then for the True you choose Execute JavaScript Code. In Settings - Code, you paste the following code below:

    
Right on. You are again ready to run the page, click on the Print button and then you will have the behavior shown below.
Picture

Note: This solution works on the Google Chrome browser. I am going to test it on the Internet Explorer/Edge browsers soon. For the Safari browser this code needs adjustment, since after the 1st Print the Hides no longer work. Feel free to post comments if you are able to adapt the code.

​


​
​Demo Application

You can login and see this solution accessing this demo APEX application.

SOTFUL - APEX Examples
https://pex.oracle.com/pls/apex/f?p=sotful_examples
Username: contact@sotful.com
Password: orclapex1

If you would like to login to the APEX Builder to see more details or export this demo application, please email me at contact@sotful.com or send your info on the SOTFUL Contact Us page, and I will gladly provide your credentials.


In my next blog post I am going to share the details for implementing a collapsible, user friendly Report Filter, using declarative Dynamic Actions. I promise taking "no time" to publish this next one :)

Best,
Sandro
15 Comments
Richard Pickles
3/23/2018 08:51:14 am

I've done something similar except using CSS @media print instead of Javascript to hide the appropriate parts of the page. This has the advantage of also working with the browsers print button and not changing the main layout when printing. You may still need some javascript to close the side menu depending on your page layout though.

Reply
Sandro Ferreira
3/28/2018 01:18:11 pm

Richard, that is an interesting advantage. You probably used the display:none CSS tag. I plan to incorporate CSS @media print on this or another post, later on. Thanks for your comment.

Reply
Jeff Wells
3/28/2018 11:09:50 am

Sandro, great blog! I have been struggling with @media print for quite a while with not so great results. Your method was very clear and more straight forward.

I replaced window.print() with parent.window.print() and found the results to be more consistent across all 3 browsers; Chrome, Firefox and IE 11.

Reply
Sandro Ferreira
3/28/2018 01:19:53 pm

Jeff, I am glad it helped! And thanks for sharing the code adjustment that you did.

Reply
Frank Downey link
4/6/2018 02:18:40 pm

Great Post Sandro.

Reply
Sandro Ferreira link
4/17/2018 01:28:57 am

Thanks Frank. I have other solutions to share.. I should blog more often.

Reply
Ronald
4/16/2018 11:37:17 pm

Hi Sandero,

Spotted a little bug in your code ...
if ( navCollapsed = 1 ) { ...
Should be ...
if ( navCollapsed == 1 ) { ...

Gr.
Ronald

Reply
Sandro Ferreira link
4/17/2018 11:16:48 am

Ronald.. good catch. This would prevent the Navigation Bar List to show collapsed after the print, in case it was collapsed before the print. I just updated it. Thanks

Reply
Prince Sarker
4/17/2018 06:19:13 am

Mr. Sandro
Thank you So Much for sharing your work(
Quickest Print Friendly in Oracle APEX).
it is very helpful to me again
thanks.
See you future .

Reply
Md. Sheikh Nasim
7/25/2018 05:45:36 am

Mr.Sandro Ferreira
Thank you very much for sharing this work.
It is help me a lot.
again thank you

Reply
MYSE
9/6/2018 05:01:53 am

Thanx alot :)

Reply
ceaser IT
3/7/2019 06:35:06 pm

Greate job sandro.i am going to run thes steps and i am sure will work it.
Sandro shortened the way (Haha) instead of installing and configuring bi publisher or jasperreport or code pl/sql
Thanks

Reply
sams
4/26/2019 04:26:19 am

Mr. Sandro

Thank you So Much for sharing your work.
it is very helpful to me
thanks.

Reply
vc
8/11/2020 01:16:04 pm

Thanks for very useful article. It saved me lots of time.
All the best.

Reply
MD.ALAUDDIN AHMED
2/18/2021 12:30:41 am

Thanks a lot

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Picture

    Sandro Ferreira

    Hi there! I am an Oracle APEX Developer, Enterprise Application Architect and Founder at SOTFUL. I've worked as an Oracle Consultant for many years, on several Oracle APEX projects and I like to learn every day. I am passionate about RAD products and building Enterprise Applications.

    Archives

    October 2018
    March 2018
    November 2016
    October 2016

    Categories

    All
    Meetup
    Oracle APEX
    Print
    RAD

    RSS Feed

    View my profile on LinkedIn
    Follow @sandrogferr
Copyright © 2015 - 2023 SOTFUL. All rights reserved.​

We build with using

We build with love using Oracle APEX
Picture