How to Print specific Region In Oracle Apex?

How to Print specific Region In Oracle Apex?

How to Print specific Region In Oracle Apex?

A Step-by-Step Guide to Printing a Specific Region in Oracle Apex

In today's digital age, printing data from web applications has become a common requirement. When working with Oracle Apex, a popular web development platform, you may come across the need to print a specific region within your application. In this article, we will explore different methods and techniques to accomplish this task effectively.

Oracle Application Express (Apex) is a powerful and versatile tool for building web applications. It allows developers to create interactive and dynamic web pages using SQL and PL/SQL. One common challenge faced by Apex developers is the ability to print specific regions of their application. Fortunately, Oracle Apex provides several features and options to achieve this goal seamlessly.

Getting Started with Printing in Oracle Apex

To print a specific region in Oracle Apex, you need to follow a series of steps. Let's dive into the details:

Step 1: Identify the Target Region

Before you can print a specific region, you need to identify the region you want to print. Oracle Apex allows you to define different regions within your application, such as interactive reports, charts, forms, or custom HTML regions. Determine which region contains the data you want to print.

Step 2: Set up a Print Button

To enable printing functionality, you should create a button or a link that triggers the printing process. Oracle Apex provides a built-in "Print" button template that you can easily add to your page. Simply drag and drop the button from the component list onto your page, and Apex will automatically generate the necessary code.

Step 3: Configure the Print Attributes

Once you have added the print button, you need to configure its attributes. In the button properties, locate the "Action" section and select the "Defined by Dynamic Action" option. This allows you to define custom logic for the printing process.

Step 4: Create a Dynamic Action

Now it's time to create a dynamic action that will handle the printing functionality. Dynamic actions are powerful tools in Oracle Apex that allow you to define custom behavior based on specific events. Create a dynamic action that triggers on the click of the print button and performs the necessary actions to print the desired region.

Step 5: Specify the Print Region

Within the dynamic action, you need to specify the region you want to print. Oracle Apex provides a built-in JavaScript function called apex.regionthat allows you to interact with regions programmatically. Use this function to reference the target region and apply the necessary print settings.

Step 6: Test and Refine

After setting up the print functionality, it's essential to test and refine the output. Run your application, click the print button, and verify if the specified region is being printed correctly. Make any necessary adjustments to the dynamic action or region settings until you achieve the desired print result.

1. Create a Region
2. Create a HTML Css Report 

DECLARE n number;
Begin n:=0;
htp.p('<table width="100%" border="1" style="border-collapse:collapse">
 < thead style="display:table-header-group;font-weight:bold" >
    < tr>
    < td> < div align="center" > ক্রঃ নং< /div> < /td>
    < td> < div align="center" > OID< /div> < /td>
    < td> < div align="center" > THAN_ID < /div> < /td>
    < td> < div align="center" > THAN_NM < /div> < /td>
    < td> < div align="center" > DIST_OID< /div> < /td>
    < td> < div align="center" > IS_ACTIVE< /div> < /td>
    < td> < div align="center" > THAN_NM1 < /div> < /td>
    < /tr> < /thead> ');

    for x in (select OID, THAN_ID, THAN_NM, DIST_OID, IS_ACTIVE, THAN_NM1 from THANAUPAZILA) loop n:=n+1;
    htp.p('<tbody style="text-align:center"">
 < tr>
        < td > '||CONV_ENGLISH_BANGLA(n)||' < /td>
        < td > '||x.OID||' < /td>
        < td > '||x.THAN_ID||' < /td>
        < td > '||x.THAN_NM||' < /td>
        < td > '||x.DIST_OID||' < /td>
        < td > '||x.IS_ACTIVE||' < /td>
        < td > '||x.THAN_NM1||' < /td>
        < /tr> ');
 end loop;
        htp.p('</table>');
        END; 
3. Goto HTML Css Report and Paste the following code
Htp.p('<a type="button1" class="button button1" class="fa fa-print" id="print" type="button" onclick="printdiv('
            'div_print1'

            ');" value="Print"><b class="fa fa-print"> Print</b></a>
 < div id="div_print1" style="margin-top:5px;" > ');

4. Goto Page Properties

  1. Function and Global Variable Declaration
  2. Paste the following code-
 function printdiv(printpage) {
                var headstr="<html>
 < head>
                < title> < /title>
                < /head>
                < body> ";
 var footstr="</body>";
                var newstr=document.all.item(printpage).innerHTML;
                var oldstr=document.body.innerHTML;
                document.body.innerHTML=headstr+newstr+footstr;
                window.print();
                document.body.innerHTML=oldstr;
                return false;
            }

            

4. Goto Page Properties

  1. Inline
  2. Paste the following code-
 .t-Region-headerItems--title {
                display: block;
                text-align: center;
            }

            .button {
                background-color: #4CAF50;
                /* Green */
                border: none;
                color: white;
                height: 3.2rem;
                padding: -2px 6px;
                text-align: center;
                text-decoration: none;
                display: inline-block;
                font-size: 12px;
                margin: 0px 0px;
                -webkit-transition-duration: 0.4s;
                /* Safari */
                transition-duration: 0.4s;
                cursor: pointer;
                line-height: 1.6rem;
                padding: 4px 8px;
                icon: "fa fa-print";
            }

            .button {
                background-color: #4CAF50;
                /* Green */
                border: none;
                color: white;
                padding: .8rem 1.2rem;
                text-align: center;
                text-decoration: none;
                display: inline-block;
                font-size: 16px;
                margin: 4px 2px;
                -webkit-transition-duration: 0.4s;
                /* Safari */
                transition-duration: 0.4s;
                cursor: pointer;
                float: right;
                width: 95px;
                icon: "fa fa-print";
            }

            .t-Button {
                text-align: revert;
            }

            .button1 {
                background-color: #0572CE;
                color: white;
                border: 2px solid #0572CE;
            }

            .button3 {
                background-color: white;
                color: black;
                border: 2px solid #f44336;
            }

            .button3:hover {
                background-color: #f44336;
                color: white;
            }

            

FAQs (Frequently Asked Questions)

Here are some common questions related to printing specific regions in Oracle Apex:

Can I print multiple regions simultaneously?

Yes, Oracle Apex allows you to print multiple regions at once. Simply include the desired regions in your dynamic action logic, and the print functionality will handle them accordingly.

Can I customize the print layout and styling?

Certainly ! Oracle Apex provides various options for customizing the print layout and styling. You can define print templates, modify CSS styles, and even apply conditional formatting to tailor the printed output to your specific needs.

Can I include headers and footers in the printed output?

Absolutely ! Oracle Apex supports the inclusion of headers and footers in the printed output. You can add custom text, page numbers, or even images to enhance the printed document's appearance and provide additional information.

Is it possible to exclude certain regions from the print output?

Yes, Oracle Apex allows you to exclude specific regions from the print output if needed. By applying conditional logic in your dynamic action, you can control which regions are included or excluded during the printing process.

Can I generate a PDF instead of directly printing?

Definitely ! Oracle Apex provides functionality to generate PDF documents instead of directly printing. By utilizing the built-in PDF printing options, you can generate high-quality PDF files that can be downloaded or shared electronically.

Can I automate the printing process?

Yes, it is possible to automate the printing process in Oracle Apex. By combining dynamic actions with scheduled processes or triggers, you can create automated workflows that generate and print specific regions at predefined intervals or based on specific events.

Conclusion

Printing specific regions in Oracle Apex is a valuable capability that allows you to extract and share data from your web applications effectively. By following the steps outlined in this article, you can easily implement the printing functionality in your Apex applications. Remember to leverage the powerful features and customization options provided by Oracle Apex to tailor the print output according to your requirements.

1 Comments

Hlo Sir

Previous Post Next Post