Forum Moderators: open
Anyone have experience with this?
Thanks!
PS I googled up a reference to this issue, but that told me to look at the SamplePad application in the help files, which I can't find.
Declarations
I put this in the Page_Load Event but it could be called from anywhere in the page:
Try
Dim pd As New PrintDocument()
pd.PrinterSettings.PrinterName = "\\ServerName\PrinterShareName"
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
pd.Print()
Catch ex As Exception
Response.Write("Error: " & ex.ToString)
End Try
Finally, here's the object reference that is passed into the Handler (Notice the printed line message is set here):
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim yPos As Single = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String
Dim printFont = New Font("Arial", 10)
line = "This is my printed Line"
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
End Sub
[edit]This works if the webserver is attached to the printer and everyone or ASPNet has print permissions on the share. Cross network I ran into RPC issues, probably permissions[/edit]
Thanks again,
Ross
setting up the printer under Settings/PrintersYes and creating a Share
This all works fine when I'm logged off too but I think permissions is your problem...
I reproduced your error (you have accessed the printer with Invalid settings.....) by removing the Everyone group's print permissions via the Printer Sharing dialogue.
I then granted the ASPNet user Print permission and it worked.
You must be logged on locally as an Administrator to make these changes.