Printing from Web Server to a connected Network Printer

Hello all,

Okay so the problem we are coming across is the ability to print from a web server to a network printer that is connected to the server.

When I run this on my local machine in my development environment it works okay but when on the live server I am having troubles.

Can anyone help me out? or what I should be setting as the Printer Name, Location.

Or is it even possible?

Thanks in advance

The code is very simple and based on examples

'create PdfViewer object
Dim viewer As New PdfViewer()

'open input PDF file
viewer.BindPdf(Server.MapPath(txtFileLocation.Text))

'set attributes for printing
viewer.AutoResize = True 'print the file with adjusted size
viewer.AutoRotate = True 'print the file with adjusted rotation
viewer.PrintPageDialog = False 'do not produce the page number dialog when printing

'create objects for printer and page settings and PrintDocument
Dim ps As New System.Drawing.Printing.PrinterSettings()
Dim pgs As New System.Drawing.Printing.PageSettings()
Dim prtdoc As New System.Drawing.Printing.PrintDocument()


'set printer name
ps.PrinterName = txtPrinterName.Text

'set PageSize (if required)
pgs.PaperSize = New System.Drawing.Printing.PaperSize("A4", 827, 1169)

'set PageMargins (if required)
pgs.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)

'print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps)

'close the PDF file after priting
viewer.Close()'create PdfViewer object
Dim viewer As New PdfViewer()

'open input PDF file
viewer.BindPdf(Server.MapPath(txtFileLocation.Text))

'set attributes for printing
viewer.AutoResize = True 'print the file with adjusted size
viewer.AutoRotate = True 'print the file with adjusted rotation
viewer.PrintPageDialog = False 'do not produce the page number dialog when printing

'create objects for printer and page settings and PrintDocument
Dim ps As New System.Drawing.Printing.PrinterSettings()
Dim pgs As New System.Drawing.Printing.PageSettings()
Dim prtdoc As New System.Drawing.Printing.PrintDocument()


'set printer name
ps.PrinterName = txtPrinterName.Text

'set PageSize (if required)
pgs.PaperSize = New System.Drawing.Printing.PaperSize("A4", 827, 1169)

'set PageMargins (if required)
pgs.Margins = New System.Drawing.Printing.Margins(0, 0, 0, 0)

'print document using printer and page settings
viewer.PrintDocumentWithSettings(pgs, ps)

'close the PDF file after priting
viewer.Close()

Hi Jonathan,


Thanks for your inquiry. There are two option for sending print to network printer. Either pass complete path of printer as following or don’t give the printer name so it will print to default printer automatically,assuming network printer is your default printer.

'set printer name
ps.PrinterName = '\systemname\printername’

Hopefully it will serve the purpose. Please correct me if there is any difference in my understanding and your requirements.

Best Regards,

Though setting the printer name to the absolute path of the network printer, the code is not working. It works from local but not from web server. Please help

Hi Ronnie,


Thanks for your inquiry. Please note printers are usually installed on user’s profile (especially if it’s a network printer, not a physically connected one such as on USB or parallel cable). When Administrator sees a printer it doesn’t necessarily mean they will be available when other user is logging on the same machine. ASP.NET applications runs as ApplicationPoolIdentity or NetworkService credential by default so the web application is unlikely to see the printers there.

There are two solutions:

1) Create an account for .NET application pool to run on, and then login as that user on the server and add the printers there.

2) Run on web site under Custom account (Identity property in site’s preferences) that is already able to work with printers.


More information about application pool usage - http://www.iis.net/learn/manage/configuring-security/application-pool-identities. Hopefully it will help you to accomplish the task.

Best Regards