Print HTML Report Using Print Button in Oracle Apex
Print HTML Report Using Print Button in Oracle Apex
Topic Introduction: In this tutorial, we will show how to print an HTML report using the Print button in Oracle Apex. In my previous tutorial, we have shown show how to create a PDF Group report using HTML & PL/SQL in the dynamic content of Oracle Apex. Here we will print that report by modifying that page.
Follow the instruction to do the task
Print way no 01:
01. Edit PL/SQL Block in Dynamic content PL/SQL source. Set the div tag Printing start point to end point. I have been given a tag with ID. This ID I use this to print a specific area.
htp.p('<div id="PrintArea">');................................htp.p('</div>');
02. Take a button Name Print
03. Take a Dynamic action against the Print Button
Action type: Execute JavaScript Code
function printContent(el){var restorepage = document.body.innerHTML;var printcontent = document.getElementById(el).innerHTML;document.body.innerHTML = printcontent;window.print();document.body.innerHTML = restorepage;}printContent('PrintArea');
04. Now Save and run this page.
To print this Region click on the Print button will show the print option.
If face any problem completing this task please feel free to contact will me. Thanks a lot.
Print way no 02:
01. Edit PL/SQL Block in Dynamic content PL/SQL source. Set the div tag Printing start point to end point. I have been given a tag with ID. This ID I use this to print a specific area. This code I have already set this to my previous report creating Post
l_result := l_result || '<div id="PrintArea">';................................l_result := l_result || '</tbody></table></div>';
02. Function and Global Variable Declaration: Write the code on this box
function printdiv(a) {var headstr = "<html><head><title></title></head><body>";var footstr = "</body>";var newstr = document.getElementById(a).innerHTML;var oldstr = document.body.innerHTML;document.body.innerHTML = headstr + newstr + footstr;window.print();document.body.innerHTML = oldstr;return false;}window.addEventListener("afterprint", (event) => {console.log("After print");window.location.reload(true);});
03. Take a button Name Print
04. Take a Dynamic action against the Print Button
Action type: Execute JavaScript Code
printdiv('PrintArea');
05. Now Save and run this page.
No comments