留言板

Printing the Report

Hiten Shah,修改在9 年前。

Printing the Report

New Member 帖子: 16 加入日期: 14-5-21 最近的帖子
Hello,

I created a portlet which contains the report. It display the graphical report means contains pie chart and bar chart .
i want to print that report.
so how can i print it???

Thank you.
thumbnail
Manish Yadav,修改在9 年前。

RE: Printing the Report

Expert 帖子: 493 加入日期: 12-5-26 最近的帖子
Hiten Shah:
Hello,

I created a portlet which contains the report. It display the graphical report means contains pie chart and bar chart .
i want to print that report.
so how can i print it???

Thank you.


Dear Hiten,

You can use jquery to print div. I'll recommend to create div id for graphs and then print that id using jquery or javascript.

Hope below link will help

1. http://www.aspdotnet-suresh.com/2013/08/jquery-print-div-content-with-css-using.html
2. http://stackoverflow.com/questions/2255291/print-the-contents-of-a-div

Kind Regards,
Manish Yadav
Hiten Shah,修改在9 年前。

RE: Printing the Report

New Member 帖子: 16 加入日期: 14-5-21 最近的帖子
Hello,
I tried whatever you said but it didn't work.

Thank you.
thumbnail
Jignesh Vachhani,修改在9 年前。

RE: Printing the Report

Liferay Master 帖子: 803 加入日期: 08-3-10 最近的帖子
Hi Hiten,

Can you please give a try using below code :



    <title>Untitled Page</title>

    <script language="javascript" type="text/javascript">
        function printDiv(divID) {
            //Get the HTML of div
            var divElements = document.getElementById(divID).innerHTML;
            //Get the HTML of whole page
            var oldPage = document.body.innerHTML;

            //Reset the page's HTML with div's HTML only
            document.body.innerHTML = 
              "<html><head><title></title></head><body>" + 
              divElements + "</body>";

            //Print Page
            window.print();

            //Restore orignal HTML
            document.body.innerHTML = oldPage;

          
        }
    </script>



    <form id="form1" runat="server">
    <div id="printablediv" style="width: 100%; background-color: Blue; height: 200px">
        Print me I am in 1st Div
    </div>
    <div id="donotprintdiv" style="width: 100%; background-color: Gray; height: 200px">
        I am not going to print
    </div>
    <input type="button" value="Print 1st Div" onclick="javascript:printDiv('printablediv')">
    </form>


Hiten Shah,修改在9 年前。

RE: Printing the Report

New Member 帖子: 16 加入日期: 14-5-21 最近的帖子
Hello,
Thank you Jignesh. Your code is working .

Thank you.