Help please: Printing with multiple printers

Hello, Happy New Year,

I have two printers, a ColorLaserJet and a Monochrome, (black), LaserJet.

Most of my printing is done on the Monochrome LaserJet, I use the ColorLaserJet specifically for one of my apps, Call it AppColor.

My System’s Default, Chip Apple M1, Memory 8 GB, macOS Sonoma 14.2.1, is set to the Monochrome LaserJet.

When I want to print on the Monochrome LaserJet with my other apps I use g = openprinter and the dialog is bypassed because it goes directly to the default printer… the Monochrome LaserJet.

When I want to print on the ColorLaserJet with AppColor I have to use g = openprinterdialog and then select the ColorLaserJet.

How can I can code AppColor to bypass the default and print with the ColorLaserJet programatically?

I’m using XOJO Version 2023 Release 4.

Thanks.

Lennox

If you have access to MBS plugins, then this will do what you’re looking for.

dim pi as new NSPrintInfoMBS
pi.printer = NSPrinterMBS.printerWithName("My Printer Name")

dim ps as new PrinterSetup
ps.SetupString = pi.SetupString

dim g As Graphics = OpenPrinter(ps)

I’m not sure how to build that setup string without the aid of the plugin though.

1 Like

I did this using external (local) files with setup’s for each printer I have to use, so I call each one per needs

I usually need to print on 2 printers different reports under the same method

This way I avoid asking to change setup each time I have to print

Thanks, but I am coding for personal, in-house, use, would prefer a solution without plugins.
Lennox

you can do it with a call to a shell

#if TargetMacOS or TargetLinux
  myShell.Execute "lpoptions -d "+aPrinterName
#Elseif TargetWindows
  myShell.Execute "wmic printer where name='"+aPrinterName+"' call setdefaultprinter"
#endif

you can get the actuel printer name with

#if TargetMacOS or TargetLinux
  myShell.Execute "lpstat -d"
  dim defaultPrinter as String = myShell.Result
  
  myShell.Execute "lpstat -p"
  ' note : lpstat -d doit donner l'imprimante par défaut actuelle
#Elseif TargetWindows
  myShell.Execute "wmic printer get name,default"
  Dim result As String = myShell.Result
#endif

these were grabbed from this forum but I don’t have the actual posts anymore

That’s a really interesting workaround.

Good idea

Thanks, will have a go at it tomorrow.
Thanks Again.
Lennox

Thanks Jean-Yves Pochez,

I found a post of yours, Printing in a multi printer setup - best approach ?
I would appreciate if you can post a simple, bare-bones, project with that code.

Kindly assist.

Thanks.
Lennox

the code I use is in that post you found …

Thanks.
Lennox

er…well…

really not mine. :face_with_raised_eyebrow:

Time ago I’ve been just looking to achieve this matter and found

So this was my startpoint

By the way,Lennox I can drop you some code if you need. (althought I guess I would need to dust off my iMac :roll_eyes: )

Hi Alberto,
I would really appreciate it.
Thanks in advance.
Lennox

Here is a project that demonstrates the concept. It prompts for the printer setup once and saves it to a file. It does that for the second printer as well. Then you can print to each printer without prompting the user again.

It’s old and was only tested on Windows.

Thnak you for your help. It will be my first example-ro-share so I really haven’t got idea about how to do. :blush:

I confirm this is the way I do (under windows)

Thanks Tim,

I am using Mac though, I will see how I can modify it.

Thanks again.

Lennox

Thanks Tim,

It compiles and runs for Mac without any issues.

My next step is to incorporate it into my apps.

Thanks again.

Lennox