Accessing Print Queue From ASP.NET
- From: murasaki1@xxxxxxxxx
- Date: 16 Feb 2007 07:27:22 -0800
Operating System: Windows 2003 Server R2
..NET Framework Version: 1.1
Web Server: IIS Server 6.0
Programming Language: VB.NET
I have been trying to find out a way to access the print queue using
ASP.NET. I want to be able to access the print queue for a particular
network printer and display each job and quantity in the Web browser.
I am importing the System.Runtime.InteropServices Namespace and this
is why I am posting this message here.
I know that by using DllImport, I can reference the winspool.drv
driver and access some Win32 API functions, but I have no idea if it
is even possible to access the print queue of a particular network
printer. I tested the following two functions on a local printer,
Adobe PDF. This is a virtual printer that gets installed when you
install Adobe Acrobat. it functions the same as any other physical
printer, but it just prints out to a PDF file instead.
The Default.aspx.vb code-behind file contains these two functions:
<DllImport("winspool.drv", EntryPoint:="OpenPrinterA", _
SetLastError:=True, CharSet:=CharSet.Ansi, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function OpenPrinter(ByVal pPrinterName As String,
_
ByRef phPrinter As Int32, _
ByVal pDefault As Int32 _
) As Boolean
End Function
<DllImport("winspool.drv", EntryPoint:="ClosePrinter", _
SetLastError:=True, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function ClosePrinter(ByVal hPrinter As Int32) As
Boolean
End Function
The Page_Load function of the Default.aspx.vb file looks like this:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim bResult As Boolean = False
Dim hPrinter As Integer
Dim pDefault As Integer
bResult = OpenPrinter("Adobe PDF", hPrinter, pDefault)
lblOpen.Text = bResult.ToString()
bResult = ClosePrinter(hPrinter)
lblClose.Text = bResult.ToString()
End Sub
As you can see, the Boolean result of the OpenPrinter and ClosePrinter
function calls are displayed in labels on the Web page. Both show
"true" when I run this page in the Web browser. I don't know if this
means anything. Now I'm trying to get to the point where I print
something to the Adobe PDF printer and access the print queue while
the PDF is still being created. Does anyone know how to do this? This
is the same thing as printing out something to a local physical
printer and grabbing the print queue information as it is printing. I
want to grab the name of the print job and the quantity of pages to be
printed. Then I want to be able to do this for multiple print jobs.
Lastly, I want to be able to do this with a network printer.
I know that this sounds kind of complicated, but I would appreciate it
if someone could point me in the right direction. If I need to
elaborate, then please let me know. Thank you in advance.
.
- Prev by Date: Please: How to insert TextBox into MS Word or ...
- Next by Date: Re: COM InterOp Interface Problem
- Previous by thread: Please: How to insert TextBox into MS Word or ...
- Next by thread: Event not firing on runtime new instance of form
- Index(es):
Relevant Pages
|