Question about Printing

Hello fellow experts. Quick printing question for you:

The following stupid simple code prints a box and some text on a printer.

    Dim WithEvents PrintDoc As PrintDocument
    Public Sub PrintTestDoc(ByVal Printer As String)
            PrintDoc = New PrintDocument
            With PrintDoc
                .PrinterSettings.PrinterName = Printer
            End With
        Catch ex As Exception
        End Try
    End Sub

    Private Sub PrintDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDoc.PrintPage
        Dim Font As New System.Drawing.Font("Tahoma", 12, Drawing.FontStyle.Regular)
        e.Graphics.DrawRectangle(Pens.Black, e.MarginBounds)
        e.Graphics.DrawString("This is a test printing from a web service.", Font, Brushes.Black, e.MarginBounds.X + 10, e.MarginBounds.Y + 10)
        e.HasMorePages = False
    End Sub

I noticed when I run this code, a window pops up that says "Printing page 1 of 1" and then disappears after the document is spooled to the print queue.

Doc comes out just fine.

My question is this: Is there any way to supress that window from popping up? My code is popping anything up.

The underlying problem here is that I am trying to get an INTRAnet web service to print to a network printer and am getting errors printing. I am now thinking that the errors could be explained by the fact that the Web Service doesn't have any UI and possibly can't popup this little window, so if I can suppress the window, perhaps it will finally work!
LVL 14
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Make sure the INTRAnet web service is running under an account that has permission to use the printer in question.  From what I've seen, PrintDocuments work fine in services without having to suppress the dialog box.
ptakjaAuthor Commented:
I am doing that (I think) through the Impersonate Attribute in my Web.Config file. I set it to true, and set a username & password that has explicit permission to print.

When I try to print, I get the following pair of errors logged to the Event Log on the server:

Event Type:      Error
Event Source:      Print
Event Category:      None
Event ID:      6161
Date:            11/23/2004
Time:            5:12:13 PM
User:            LUCY\ASPNET
Computer:      LUCY
The document ActiveReports Document owned by ASPNET failed to print on printer \\ejps01\dnmskinbatch. Data type: NT EMF 1.008. Size of the spool file in bytes: 65536. Number of bytes printed: 0. Total number of pages in the document: 1. Number of pages printed: 0. Client machine: \\LUCY. Win32 error code returned by the print processor: 1326.  

Event Type:      Error
Event Source:      Print
Event Category:      None
Event ID:      45
Date:            11/23/2004
Time:            5:16:03 PM
User:            LUCY\ASPNET
Computer:      LUCY
Document failed to print due to GDI/Driver error in rendering.

The weird thing is that the User shown above is NOT the same as the one I set up in the web service. Should it be? When I make a change to the web.config file, do I need to do anything to the server, like reboot it? Or restart the aspnet_wp?

If I remember correctly, the Web.Config file overrides settings in the Machine.Config file. Right?

I have tried differnet printer drivers as well including the PS, PCL5 & PCL6 for my HP laser printer.
I think it may be a different matter when it comes to services.  I know there is a way to impersonate a process on a web server, not sure how.  (I'm more of a System Admin and Windows Forms programmer, not ASP.NET web though...)  You are however picking up on the same thing I am, the account needs permission.  The error "Document failed to print due to GDI/Driver error in rendering. " might be when your software is trying to get the page settings for the PrintDocument, but doesn't have permission to access the printer.

The best thing I can think of is to configure IIS to run that one page as a user that has permission to the printer, or configure the printer to allow LUCY\ASPNET to print, or configure the entire application to run under the permission of a user who has permission to print...

As far as impersonation of the pages, I found:

Hope this helps!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ptakjaAuthor Commented:
Not exactly the answer but you confirmed my suspicion. Found out that the permission problem lies in the print server, which is not the same box as the web server.

Thanks anyway!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.