How to use OpenPrinterDialog once for multiple print jobs

I am trying to figure out how to call OpenPrinterDialog once while printing several print jobs, primarily to allow the user to select the desired printer.

The majority of my users are on Mac OS X, however, I do have the occasional Windows user.

I can’t really see how to store the settings from a call to OpenPrinterDialog and re-use them.

See this discussion: https://forum.xojo.com/35613-choosing-special-printer-without-printer-dialog-in-windows-app

You can save and restore PrinterSetup.SetupString.

[quote=291265:@Tim Hare]See this discussion: https://forum.xojo.com/35613-choosing-special-printer-without-printer-dialog-in-windows-app

You can save and restore PrinterSetup.SetupString.[/quote]
I did see that, however, since the PrinterSetup is not the dialog box which lets the user select the desired printer, but rather the PrinterDialog (using OpenPrinterDialog), I assumed that the desired output printer is not stored in the PrinterSetup.SetupString.

Is this not right?

Actually, I just tried this with the code below and the print job printed to two different printers.

[code] Dim settings as String
Dim g As Graphics
Dim p As PrinterSetup
p = New PrinterSetup
If p.PageSetupDialog Then
settings = p.SetupString
g = OpenPrinterDialog§
If g <> Nil Then
g.DrawString(“Hello World”, 50, 50)
End If
End If

g = Nil

If settings > “” then
p.SetupString = Settings
g = OpenPrinter§
If g <> Nil Then
g.DrawString(“Hello World”, 50, 50)
End If
End If[/code]

Reverse these lines (save the setupstring after you select the printer).

[quote=291327:@Tim Hare]Reverse these lines (save the setupstring after you select the printer).

[/quote]
I did reverse the two lines with the result going to two different printers. See below:

[code] Dim settings as String
Dim g As Graphics
Dim p As PrinterSetup
p = New PrinterSetup
If p.PageSetupDialog Then
g = OpenPrinterDialog§
settings = p.SetupString
If g <> Nil Then
g.DrawString(“Hello World”, 50, 50)
End If
End If

g = Nil

If settings > “” then
p.SetupString = Settings
g = OpenPrinter§
If g <> Nil Then
g.DrawString(“Hello World”, 50, 50)
End If
End If[/code]

Be careful, if you restore a setup string to the wrong printer, your app will crash without raising an exception.

Does the sample project I posted on the other thread work? I’m running out of ideas.

I had the same problem with the sample project. When the dialog box appears, and you select the desired printer, the output goes to the correct printer. When the dialog box does not appear, all print output goes to a single printer. It doesn’t matter if in the System Preferences I choose the printer or select “Last Printer Used.”

[quote=291343:@John McKernon]Be careful, if you restore a setup string to the wrong printer, your app will crash without raising an exception.

[/quote]
I will keep an eye out for this. What I am trying to do is have a dialog box appear, then have all output to the printer that was selected in that dialog box.

For example, I want to print a group of letters to a selection of customers (such as a welcome letter, and information about a product they bought). I want to have one dialog box appear at the beginning and be able to direct all output to a specific printer. When everything goes to the default printer, all is fine. The problem occurs when I want all the output to go to a different printer. The first letter goes to the correct printer, but then all the rest go to the default printer. It doesn’t matter if in the System Preferences I choose the printer or select “Last Printer Used.”

If you can’t direct the output of multiple graphic objects to a single printer (without a dialog box before each print job), is there a way to build all the output to a single graphics object and just put a page break between each page?

For your use case, that is the way I would do it. Graphics.NextPage inserts a page break.

I’m going to have to do some testing on Windows 10.

[quote=291572:@Tim Hare]For your use case, that is the way I would do it. Graphics.NextPage inserts a page break.

[/quote]
Ok. Thanks.