In 2022 in response to a query about disabling duplex printing, Eric Williams suggested the best way was to make each page a separate print job. Now, 4 years on, is Eric’s suggestion still the best/only way to control this programmatically? I cannot find anything in either the printer setup dialog nor the XOJO printing documentation which addresses this. What have I missed?
Mac Pro M3, Tahoe 26.5.2, XOJO 26.2
Naturally, I can’t help but enthusiastically agree with the advice you already found. 
On the Mac, duplex printing is controlled in the Print dialog, not usually the Print/Page Setup dialog. This is why the PrinterSetup.Settings string has no effect on this setting.
A few print settings that are configured in the Print dialog are available in the Graphics object that it returns, such as first page and last page and how many copies to print. These are common to all printers, unlike duplex printing, which is why they are made available and duplex is not.
You could probably dig around in the platform-specific APIs to find ways of working around this, but I suspect my original advice is a lot easier.
Also - I’ll just ask why you want to disable duplex. This really should be under the control of the user unless you have very good reasons for not supporting it.
if this is for macos only (its also ok for linux)
you could try to set the “sides” option of lpoptions shell command
something like
Dim sh As New Shell
sh.Execute("lpoptions -p ""Printer_Name"" -o sides=two-sided-long-edge")
' short edge: sides=two-sided-short-edge
' off: sides=one-sided
PS: not tested.
Thank you, Eric. Actually, do want to allow the user to control one- or two-side printing (when the printer supports it). I know how to log into a printer and change the defaults, but of course that isn’t doing it within the application. It’s a shame XOJO doesn’t provide a way to a) query the selected printer and b) where possible, expose the duplex printing choice in the print dialog.
I have noticed on my own printer if I had selected one-side printing for the last job I had printed via any application, my XOJO application will print one-sided. Ditto if the prior print job had been two-sided. Probably absent a further duplex printing instruction the printer simply continues with whatever happens to be the current duplex setting.
Likely the obstacle for XOJO to control this is the proliferation of printer types and drivers.
Thank you Jean-Yves. My need is indeed for MacOS only. I shall certainly try your suggestion.
But this is already done by the operating system. If you already want to allow the user this option, why do you need to do this programmatically?
I don’t follow you. A user is running my program. When user decides to print, the page setup dialog appears, allowing choice of printer, paper size, orientation, and scaling. No option to choose single or duplex printing. User can choose “Cancel” or “OK”. Where do the operating system choices come into this?
You’re describing the Page Setup dialog. The duplex options appear in the Print dialog.
1 Like
Thanks, Eric. The program I was changing for one-sided printing was a really old one (2017) I only recently had need to run. It used the PageSetupDialog and the long-deprecated OpenPrinter (!); now it only uses ShowPrinterDialog and all is well. Thank you for pointing me in the right direction. No doubt other problems lurk silently in that old code, and I plan to move it to API 2.