• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2852
  • Last Modified:

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)
        Try
            PrintDoc = New PrintDocument
            With PrintDoc
                .PrinterSettings.PrinterName = Printer
                .Print()
            End With
        Catch ex As Exception
            Throw
        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
        Font.Dispose()
    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!
0
ptakja
Asked:
ptakja
  • 2
  • 2
1 Solution
 
LacutahCommented:
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.
0
 
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
Description:
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
Description:
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.
0
 
LacutahCommented:
I think it may be a different matter when it comes to asp.net 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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspnetimpersonation.asp

Hope this helps!
0
 
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!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now