1

I have a sharepoint 2013 page with a infopath form. I would like this page to contain a button that only prints the specific form ignoring the rest of the page.

I have found the below script (source: https://social.technet.microsoft.com/Forums/sharepoint/en-US/98da14d4-9447-4665-8b3a-fee558c4809f/print-specific-webpart-of-a-page-in-sharepoint?forum=sharepointcustomizationprevious).The Problem is I don't think I am identifying the "WebPartelementID" correctly.

Script:

<input type="button" OnClick="javascript:void(PrintWebPart())" value="PrintWeb Part">
<script language="JavaScript">
//Controls which Web Part or zone to print
var WebPartElementID = "<WebPartElementID>";
//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.print();
   }
   }
< /script>

I am very open to other ways to achieve this if anyone has a better idea

1 Answer 1

1

If anyone is interested I made this script work. Looking at the script in developer tools on chrome the ID you need is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.