4

I have a MOSS 2007/WSS 3.0 Site that acts as a document repository. There is a search web part that displays results in the form of a grid. Each item has a checkbox, User can select multiple documents of various formats and when they click on a print button, the data from each of these documents must be bulk printed. The printing has to be done at client side and I cannot implement any third party software but need to get this achieved. What is the best solution for this requirement?

2 Answers 2

2
+50

I don't know if this will work for 2007, as 2007 has no printing option. You'll need to use the browser printing options that you can access.

You can make a recursive method that calls a new browser to print when opened (same way the browser handles printing).

Create a webpart, webpart needs a button... when clicked it needs to scan the webpage to see what is selected, from that you can create an array that stores all the URLs for selected documents, now loop through each selected array item and passing the URL to this method:

private void PrintHelpPage(string UrlDocument)
{
    // Create a WebBrowser instance. 
    WebBrowser webBrowserForPrinting = new WebBrowser();

    // Add an event handler that prints the document after it loads.
    webBrowserForPrinting.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(PrintDocument);

    // Set the Url property to load the document.
    webBrowserForPrinting.Url = new Uri(@UrlDocument);
}

private void PrintDocument(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    // Print the document now that it is fully loaded.
    ((WebBrowser)sender).Print();

    // Dispose the WebBrowser now that the task is complete. 
    ((WebBrowser)sender).Dispose();
}

UrlDocument is the URL your passing from within the array loop that you're iterating through!

I don't know if it's just going to run through all at once populating the print spool (shows multiple opened browsers) or one at a time! My guess is all at once but they should close as soon as the command is sent to the print spool.

Or you can loop through the controls within a page, check to see if the checkbox control is checked and pass the value... this will loop through all checked items.

private void btnAdd_Click(object sender, EventArgs e) 
{ 
     foreach(Control c in Page.Controls)
     {
           if (c is Checkbox)
           {
               CheckBox cb = c as CheckBox;
               if (cb.Checked == true)
               {
                   PrintHelpPage(cb.Text)
               }
           }
     }
}

The code above won't work as it got some mistakes but it's almost there to work as you want! I'm sure the checkbox text is not the value but the above code will show you how to go about doing it. Or, as I said, do it through an array looping through within the same method above (click event).

http://msdn.microsoft.com/en-us/library/b0wes9a3(v=vs.90).aspx

2
  • Won't that send the print from the Server though? The user won't be able to pick a printer and so on. Ingenious nonetheless. Commented Nov 13, 2013 at 19:01
  • yes that is correct, unfortunatly its using the browser printing options, if you were to click on the print button on the browser it would print using the default set printer! but it works :)
    – Ali Jafer
    Commented Nov 15, 2013 at 8:34
1

The best you're going to be able to do is to just get the collection of URLs of the selected files and call window.open() on all of them. Due to the nature of the web, and the security involved in keeping things safe, the browser has very little control over the application once it has opened.

You could use ActiveX, but you can only deal with Office documents, and the user has to be using 32bit IE, with the URL of the web app in the Local Intranet zone, and the web app has to be using Windows Auth.

Your Answer

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

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