Friday, February 5, 2016

How to add Print Option to SharePoint Page to print one particular web Part?


<input type="button" ID="printBtn1" OnClick="javascript:void(PrintWebPart())" value="Print">

<script language="JavaScript">

//Controls which Web Part or zone to print
var WebPartElementID = "WebPartWPQ2";

//Function to print Web Part
function PrintWebPart()
{
var bolWebPartFound = false;
if (document.getElementById != null)
{
//Create html to print in new window
var PrintingHTML = '<HTML>\n<HEAD>\n';
//Take data from Head Tag
if (document.getElementsByTagName != null)
{
var HeadData= document.getElementsByTagName("HEAD");
if (HeadData.length > 0)
PrintingHTML += HeadData[0].innerHTML;
}
PrintingHTML += '\n</HEAD>\n<BODY>\n';
var WebPartData = document.getElementById(WebPartElementID);
if (WebPartData != null)
{
PrintingHTML += WebPartData.innerHTML;
bolWebPartFound = true;
}
else
{
bolWebPartFound = false;
alert ('Cannot Find Web Part');
}
}
PrintingHTML += '\n</BODY>\n</HTML>';
//Open new window to print
if (bolWebPartFound)
{
var PrintingWindow = window.open("","PrintWebPart", "toolbar,width=800,height=600,scrollbars,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);

// Open Print Window
PrintingWindow.window.print();
PrintingWindow.document.close();

}
}
</script>

1 comment:

  1. Coin Casino - No deposit bonus codes 2021
    How to Claim Bonus Code: Just Register and claim ⭐ No deposit welcome 더킹카지노 회원가입 bonus at the first Coin Casino, You will get free chips 더나인카지노 and cash 코인카지노 가입 that งานออนไลน์ will 더킹카지노 조작 enhance your game.

    ReplyDelete