The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to add Print option in UI page

Deepthi25
Giga Expert

Hi team,

Please suggest me how to add print option in UI page, i have my HTMl code and I need to add button down of ui page once they click that button it should give us the windows option to print please suggest

1 ACCEPTED SOLUTION

Alok Kumar2
Tera Expert

Hi,

Can you try once with the below button in your html code. Just the below code any where and you don't need to define this function in your client script.

<button onclick="print()">Print
</button>

find_real_file.png

find_real_file.png

 

Note: Please mark this as correct or helpful if it helps!!

View solution in original post

7 REPLIES 7

I am trying to print a UI Page that is being rendered in a dialog box. When I try this print script it is trying to print just a section of the form and not my dialog box - then redirects to the UI page but without any of the scoped information. 

Do you have any suggestions for being able to print the dialog box only?

find_real_file.png find_real_file.png

Hi lsilvaroli,

You can put the contents of your html inside a div with an id, then pass that id to the print function.

You can refer the below UI page's HTML code to get your code working.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<style>
	table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

tr:nth-child(even) {
  background-color: #dddddd;
}
</style>



<h2>HTML Table</h2>

<div id="custom">
<table id="tableCustom">
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
</table>
	<button onclick="printDiv('custom')"/>Print
	</div>
	<script>
 
  function printDiv(divName) {
		var printContents = document.getElementById(divName).innerHTML;
	    var originalContents = document.body.innerHTML;
		document.body.innerHTML = printContents;
		window.print();
		document.body.innerHTML = originalContents;	 
}
 
</script>
</j:jelly>

This first sets the document body to the content of your div then shows the printable page then once that is done, it replaces with the original contents. Let me know if this works.

 

NOTE : Mark this as correct if it works!!

Hi @Alok Kumar ,

Your answer for pdf generation works good!!

 

I used Bootstrap table layout, your solution generates pdf but it is not as per bootstrap design.

Also, there's no CSS included, any possibility on including CSS for pdf generation.

 

Could you please let me know the possibility for inclusion of CSS/Bootstrap?

Hope you would be helpful for me.

 

Thanks,

Priyatham.