0

I have a problem when trying to print to shared printer from my VB.NET app. This is my code...

print1.PrinterSettings.PrinterName = "Printername"
print1.Print()

When I try to run it, I get this error:

Setting to access printer "printer Name " are not valid.

But, it is works fine if I set this printer to be the default printer.

How can I change the default using VB.NET?

Paul
  • 4,160
  • 3
  • 30
  • 56
s-dept
  • 183
  • 1
  • 5
  • 17
  • Maybe you don't have the printer name correct. Try looping through the available printers to make sure. – LarsTech May 09 '18 at 15:57
  • [Here is a C# solution](https://stackoverflow.com/questions/971604/how-do-i-set-the-windows-default-printer-in-c?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa). You should be able to [convert](http://converter.telerik.com/) that code to VB.Net – Icemanind May 09 '18 at 15:59

1 Answers1

0
    PrintDialog1.Document = PrintDocument1
    PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
    PrintDocument1.PrinterSettings.PrinterName = "Microsoft Print to PDF"
    With PrintDocument1
        .PrinterSettings.DefaultPageSettings.Landscape = False
        .PrintController = New System.Drawing.Printing.StandardPrintController()
        .Print()
    End With
Bashi Lenny
  • 51
  • 1
  • 2
  • This is a printout that is being sent to a listview. I'm printing to a virtual PDF printer which is not my windows default buy is the VB default. You can also make that a textbox instead so that you dont have to edit the code everytime you want to change the printer. Sorry, not so good at explaining. – Bashi Lenny Dec 21 '18 at 14:59