I have two printers that I print to. My default printer is an A3 bubblejet, the other printer is a thermal label printer. I want to be able to select the other printer and set it’s preferences using the OpenPrinterDialog and then save the setup string to reuse next time I print this report.
This seems to work OK when the label printer is the default - I can save the setup string and revert the default back to the main printer, but from a user experience perspective I don’t want to have to tell my clients to change their default printer before saving the settings then change the default back.
I know I could adjust the registry (i.e. create my own printer selection dialog) then present the printersetup.pagesetupdialog, save the setup string and change the default back. But isn’t Xojo supposed to be easy enough for beginners?
It should work regardless of which printer is the default. If the user hasn’t saved a setup yet, you go through the dialog, otherwise you use the saved setup. What sorts of issues do you run into when the label printer isn’t the default? How are you restoring the saved setup?
I had a bit of a problem with this because I have to work with printer servers of all kinds of versions.
[code]Method ReadPrinterString
with a p parameter by byref as printersetup
Dim f, fs As FolderItem
Dim bs As BinaryStream
Dim mb As MemoryBlock
fs = SpecialFolder.Documents.Child(App.kPrinterStringFile)
f = New FolderItem(fs)
If f <> Nil And f.Exists Then
// retrieve the setup string from the file if it exists
bs = BinaryStream.Open(f, False)
mb = DecodeBase64(bs.Read(bs.Length))
Try
p.SetupString = mb
Catch e As IOException
MsgBox(“Error loading prnsetup”)
End Try
Else
If p.PageSetupDialog Then
// give the user a chance to create a new setup string
mb = p.SetupString
bs = BinaryStream.Create(f, True)
bs.Write(EncodeBase64(mb))
End If
End If
Thanks Michael & Tim. My problem is not saving or loading the printer setup. It is that the initial setup string is for the default printer not the printer I want to use, so I don’t in this case have the label sizes available. What I need to be able to do is select the printer as part of the pagesetupdialog.
I use my method to print out to multiple printers. Use a separate setup file for each one. The first time through, you have to set Windows default printer to the one you want to setup. After you setup that one, change the Windows default printer and setup that one. A bit long winded but it works for me. I only have about 6 users that need two different printers.
Since you need to be able to select a label size, you do need to do some extra work. You can declare into winspool.dll and get a list of printers via EnumPrinters, then set the default printer via SetDefaultPrinter. Or inform the user that as part of the software’s inital setup, they need to temporarily set the label printer as the default and run through xyz procedure.
Btw, do they need to be able to select the label size? When I’ve used a thermal printer in the past, I just had to set the margins small (the default of 1 inch is way too big) in the pagesetupdialog and the printer defaulted to whatever paper was loaded.
And just to make things even more difficult I need to save the printer setup after I’ve selected the printer & turned off the autocut feature which isn’t available in the printersetupdialog.
You may have seen my rants about Xojo iOS not even supporting any printing.
In defence of Xojo for the Desktop part, I must admit that printer support has always been a big problem in any platform. Especially Windows, where you never know what kind of kitchen sink users employ to output.
Too bad it makes zero financial sense to do so. Xojo couldn’t possibly charge enough more to cover the costs of implementation and worse, maintenance. At this point, it would be a net loss to the community.
What I want to do is to save and reload printer settings.
The string I am saving is the p.SetupString where p is PrinterSetup.
I was saving it to a settings file that my app already writes but it doesn’t look like “one string” but many settings. Here’s a sample.
Some as you can see is in binary. I have added Encode64 and Decode64 to this and if I bring that back in and declode it and assign it to pagesetup object .PrinterSettings … it doesn’t really reload anything previously saved that I can tell.
So I guess my problem is what I’m doing isn’t working and it’s very similar to what Michael posted.
The other thing is saving several printer settings for different printers… so perhaps one per file.
Should the file be named after the printer name?
[quote=328702:@Christian Schmitz]On mac you can use NSPrintInfoMBS class to edit it.
For Windows use WindowsDeviceModeMBS .
This allows you to change printer without dialog.[/quote]
Christian I really don’t care about changing it or printing without a dialog. I just want users to be able to for example select the tray of their printer or choose landscape and have our app “remember” that print setting and reload it when they print next time.
Right now when I save and reload the printer settings string it doesn’t do anything… no setting gets reloaded properly.
Should I use the MBS ones to save and reload the settings? Or is that just to be able to change items in the printer settings in code?
'save printer setup
psSQL = db.Prepare("UPDATE Settings SET Value = ? WHERE Name = 'Printer Settings'")
psSQL.BindType(0,SQLitePreparedStatement.SQLITE_TEXT)
psSQL.SQLExecute(ps.SetupString)
'retrieve the string
dim rs as recordset = db.SQLSelect("SELECT Value FROM Settings WHERE Name = 'Printer Settings'")
ps.SetupString = rs.Field("Value").StringValue