Adding Print capabilities to Project Detail Pages
By blurg64
A user in the Project Server forums asked a question this week about whether it was possible to add printing capability to the Project Detail Pages in order to allow the ‘forms’ to be printed out as there is no print button available on the ribbon.
Out of the box, the printing capability in the Project Web Application is limited to the grids, including the schedule grids that are visible in a schedule PDP and uses a custom page to render the information as can be seen below.
After a little experimenting with the Internet Explorer printing, it seems that PDP’s can be printed quite well directly from the browser, so I thought I would try and pull together a ribbon feature that enables PDP printing.
The feature consists of XML button definition and a little piece of JavaScript to determine if the button will be enabled or not. This is important so that the button can be disabled when the user is on the schedule page that has it’s own grid based printing function like the picture above. For the purposes of this feature, I have gone the quick route and do the check based on the name of the page, in this case if the page is called schedule.aspx the button will be disabled. You may need to modify this check if your schedule based PDP(s) have a different name.
The element.xml looks like this:
[sourcecode lang=”xml”]
<CustomAction Id="Ribbon.Tabs.PDP.Home.Print”
Location="CommandUI.Ribbon">
<Group Id="Ribbon.Tabs.PDP.Home.Print”
Sequence="60”
Description="Print Custom Group”
Title="Share”
Command="EnableCustomGroup”
Template="Ribbon.Templates.Flexible2">
<Button Id="Ribbon.Tabs.PDP.Home.Print.PrintPDP”
Sequence="40”
Command="PrintPDP”
Alt="Print”
Image16by16=”/_layouts/$Resources:core,Language;/images/ps16x16.png”
Image16by16Top=”-96”
Image16by16Left=”-160”
Image32by32=”/_layouts/$Resources:core,Language;/images/ps32x32.png”
Image32by32Top=”-288”
Image32by32Left=”-128”
LabelText="Print”
TemplateAlias="o1”
ToolTipTitle="Print”
ToolTipDescription="Print the contents of the PDP”/>
<MaxSize
Id="Ribbon.Tabs.PDP.Home.Scaling.Print”
Sequence="140”
GroupId="Ribbon.Tabs.PDP.Home.Print”
Size="LargeLarge”/>
<CommandUIHandler Command="EnableCustomGroup”
CommandAction="javascript:return true;” />
<CommandUIHandler Command="PrintPDP”
CommandAction="javascript:window.print();”
EnabledScript="javascript:
function disablePrintForSchedule() {
var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf(‘/’) + 1);
if (sPage.toLowerCase() == ‘schedule.aspx’)
{
return false;
}
else
{
return true;
}
}
disablePrintForSchedule();”
/>
[/sourcecode]
The process of building the feature is exactly the same as outlined in http://epmsource.com/2011/12/13/hiding-disabling-ribbon-items-in-project-server-part-ii/ but substitute the above code into the Element.xml file and change the feature name accordingly.
Once the feature is deployed and activated a Print button should available on the PDP ribbon that when clicked will invoke the Internet Explorer print dialog.
From my preliminary testing, the output is pretty good, as can be seen from this ‘Print to XPS’ below:
I have uploaded the full source to Skydrive which can be downloaded from the link below.
Happy PDP printing