OpenPrinter(ps) does not preserve Printer/PrinterSetup selection

Hello everyone,

It seems that the OpenPrinter(ps) doesn’t really use the printer/page setup selection that is in ps (loaded from previous saved parameters) and prints to the default printer, while OpenPrinterDialog(ps) works as expected but it opens a dialog. Is there a way to work around this, because I need to send reports to different printers, pre-selected for each report, without the user needing to choose which printer each time.

Thanks in advance for any suggestions.

Share some code. How are you reloading the printer setupstring?

Just verified this works. Xojo 2014r2.1, Windows 7.

Thank you Tim,

Here is the code

[code] Dim ps As New PrinterSetup
Dim mb As MemoryBlock = DecodeBase64(s)

ps.SetupString = mb
Catch e As IOException
Return False
End Try

ivGraphics = OpenPrinter(ps)
ivPrxScaleFactor = ps.HorizontalResolution / 72.0
ivPryScaleFactor = ps.VerticalResolution/ 72.0[/code]

s holds the string (saved) with the ps.SetupString (encoded in Base64).

I also would like to say again that this method works if I use OpenPrinterDialog instead of OpenPrinter.

I tried it in Windows 7 and Windows 8 and it doesn’t change form the default printer…
Any ideas?

Try this project:

click on each button and select a different printer. then click them alternately and see which printer is chosen.

Thanks Tim I will check it out right away…

Thank you very much Tim,
your example works. It seems I was missing the ps.PageSetupDialog which seems to make the difference.

I will change the code in my project and verify that it works too…

Thanks Tim, everything works now!
I appreciate you help! :slight_smile:

I can’t see how Tim’s example should work.

When I try it, and choose one printer with the first button, and another printer with the other button, then after that both buttons will print to the last chosen printer, and not to different printers as I had assigned them. I’m testing this on OS X 10.9.

Does this really work for someone here?


I’ve figured out how to choose the printer on OS X now, though:

By using the function CorePrinting.SetDefaultPrinter() from the MacOSLib, I can preselect the Printer I want to print to.

Hi Thomas,

It worked for me, even though I think I had to press each button twice for it to work correctly. I think it has to do with the page setup preceding the printer selection…

Fotis, you’re using Windows, aren’t you? That would explain it: It works on Win but not on OSX.

I am actually developing on Mac, but this was needed for a Windows App. However, I first tested it on OS-X so I think it works on the Mac side as well.