[quote=290593:@Tim Hare]I posted a sample project in this thread: https://forum.xojo.com/17453-openprinter-ps-does-not-preserve-printer-printersetup-selection
Try it out.[/quote]
Hi Tim,
I tried your sample project, thank you (your code below). The issue I see here is that when calling the PageSetupDialog the attributes for the page size and source always default and preload to the currently selected “default” printer properties (in Windows 10).
In your example if the page sizes for both printers happen to be the same, then it obviously works. In my case I have a label printer (1.1" x 3") and a laser printer (8.5" x 11"). If the label printer is selected as a default in windows then I have no option of selecting anything other than the label sizes available to the label printer in PageSetupDialog. If the laser is selected as the default printer then the reverse is true.
In your sample application you look to be calling the PageSetupDialog before the OpenPrinterDialog. So it looks like your only choices for page attributes is related to the current default printer, not what is or will be selected from the printer dialog. I might be missing something.
The only way I see the sample working is if both printers happen to use the same page setup preferences, which might be the case in many applications (8.5 x 11), but it doesn’t seem like a workable solution if the page size is different.
[code] dim ps as new PrinterSetup
dim f as FolderItem
dim txtin as TextInputStream
dim txtout as TextOutputStream
dim g as Graphics
f = GetFolderItem(“printer1.txt”)
if not f.exists then
if not ps.PageSetupDialog then return
g = OpenPrinterDialog(ps)
if g = nil then return
txtout = TextOutputStream.Create(f)
txtout.write ps.SetupString
else
txtin = TextInputStream.Open(f)
ps.SetupString = txtin.ReadAll
g = OpenPrinter(ps)
end
g.DrawString(“Printer 1”, 30, 30)
[/code]
You can simulate this behavior very easily, assuming you have two printers installed that have different page attributes. I’d try a regular printer and the Microsoft XPS or Microsoft Print to PDF printer. If you have a label printer that’s even better.
- Select one of the printers as the default in windows.
- Run your app.
- When the page setup dialog loads take note of the list of paper sizes in the drop down. You will note these will always be what is selected as the default printer, regardless of what is chosen in your app.
Your application WILL print to different printers, but the page setup cannot be set to anything other than the currently selected default printer.
Unless I am missing something, there seems to be an issue here with Xojo’s implementation of this. It may have been a Windows update that broke this but I do remember dealing with this back in Win7 (my memory may be failing). What we really need is a way to open the PageSetupDialog and pass a printer to it, so it can then show the available page sizes, sources and margins specific to the passed printer, not the “default” printer. The current implementation makes it impossible to print to different printers with different page sizes than the default printer. Unless of course you manual set the default prior to calling PageSetupDialog.
Please tell me I have overlooked something, I’d really like to get this working.
EDIT: I will mention that this new weird setting in windows that sets the default printer to the last one used actually improves the chance of this working, all you have to do is press your button twice and it will load the updated page attributes. I did notice a user in the other thread mentioned having to press it twice to get it to work, I suspect this is why.
Thanks Tim, any input appreciated!