Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I would like to print everything in a newform.aspx/editform.aspx modal dialog. I was considering creating a Web Part or a bit of JavaScript that was nothing more than a print button that specified the current window but I wasn't sure if that would work...

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can create a Custom Action which will add a print button to your Newform.aspx and EditForm.aspx forms, and in the Command you can define a javascript to print current window. See sample below:

Example for NewForm.aspx

 <CustomAction
  Description="Print me"
  Title="Show Me"
  Id="{E538E8C7-65DA-454E-AD87-4A603B6CC569}"
  Location="CommandUI.Ribbon.NewForm"
  RegistrationId="100"
  RegistrationType="List"
  Sequence="0"
  Rights="ViewListItems"
  xmlns="http://schemas.microsoft.com/sharepoint/">
    <CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
      <!-- Define the (UI) button to be used for this custom action -->
      <CommandUIDefinitions>
        <CommandUIDefinition Location="CommandUI.Ribbon.ListForm.New.Page.Edit.Controls._children">
          <Button
           Id="Ribbon.ListForm.Display.Manage.PrintMe"
                 Sequence="0"
         Command="PrintPage"
          Image32by32="~site/_layouts/Images/BingSearch/bing32.png"
          Image16by16="~site/_layouts/Images/BingSearch/bing16.png"

          LabelText="Print me"
          Description="Print me description"
          TemplateAlias="o1"/>

        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <!-- Define the action expected on the Print button click -->
        <CommandUIHandler Command="PrintPage" CommandAction="javascript: window.print()" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
share|improve this answer
    
I like this idea much better than my original! I was mostly worried that I wouldn't be able to print JUST the modal window (ignoring the parent window). –  James Grizzle Jun 26 '12 at 17:28
    
Parent window in this case would be EditForm.aspx or NewForm.aspx (Modal Dialog), so I don't see a problem here. Also this fulfils your requirement? –  Falak Mahmood Jun 26 '12 at 17:33
2  
For what it's worth, if you don't want to bother with Visual Studio, this also works via SharePoint Designer. Open the site, navigate to the details page of the appropriate list, highlight the custom actions area, use the New Custom Action button that is in the main ribbon at top left, then, copy the above CommandAction javascript and paste it into the 'Navigate to URL' field. –  bkwdesign Jun 26 '12 at 17:46
    
That can also be done with SP Designer but creating a custom action in Feature within a WSP is scalable solution especially if you have different Farms (Development, Test, Production). You WSP may contains all your resources including Features, site definitions, assemblies, Web Part packages, class resources etc etc, and also can be deploy to the entire farm in one go, with Features can be activated to sites as per Users likings. –  Falak Mahmood Jun 26 '12 at 18:15
    
I attempted to try the solution using SP Designer as you instructed by placing CommandAction="javascript: window.print()" in the Navigate to URL field but i get an error Could not save List change to server. 'javascript' is an unexpected token, Expecting white space Line 1, position 545? ideas? –  user13177 Nov 24 '12 at 0:10
add comment

Better CommandAction approach here, because it gets all dialog content w/o the underlying page.

Weakness, doesn't honor InfoPath Page breaks.

http://social.technet.microsoft.com/Forums/en-PH/sharepointgeneralprevious/thread/9e6400bf-7208-4498-ad36-e8ccc022a626

           CommandAction="javascript:
                      var patt = /.+_FormControl.+__ViewContainer/gi;
                      var alldivs = document.getElementsByTagName('div');
                      var printpageHTML = '';
                      for(var i=0; i&lt;alldivs.length; i++){
                        if(patt.test(alldivs[i].id)){
                          printpageHTML = '&lt;HTML&gt;&lt;HEAD&gt;\n' +
                                          document.getElementsByTagName('HEAD')[0].innerHTML +
                                          '&lt;/HEAD&gt;\n&lt;BODY&gt;\n' + 
                                          alldivs[i].innerHTML.replace('inline-block','block') + 
                                          '\n&lt;/BODY&gt;&lt;/HTML&gt;';
                          break;
                        }
                      }
                      var printWindow = window.open('','printWindow');
                      printWindow.document.open();
                      printWindow.document.write(printpageHTML);
                      printWindow.document.close();
                      printWindow.print();
                      printWindow.close(); 
                      SP.UI.Notify.addNotification('Exiting!');                           
                       ">
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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