The setupstring prior to macOS 26 is not read now

Apple seems to have changed the format of the string. It was plain xml until now, and it’s now in the binary plist format.
I suspect any old string will be compatible with older systems and the new one should stay compatible with the newer systems.
Now, to convert from the old one to the new one (or the other way around), you could try to convert from one format to another; I don’t know if it’ll work specifically for a setup string, but you may give it a try:

Save your setupstring to a temporary file (the utility converts existing files only, no input stream). Then, use either of these using a shell:
plutil -convert xml1 YourFile.plist
plutil -convert binary1 YourFile.plist
(the former converts to xml (legacy format) and the latter to binary (new format))

Then re-read the file, which will hold the other version. Apply it to the setupstring and cross your fingers.
Of course, you’ll have to first validate the source string: if it’s xml on a system prior to MacOS 26 or it’s a binary string on MacOS 26 or later, you don’t need to do the conversion.

From the documentation, here’s an example of how to get some properties:


Var settings As String
Var p As New PrinterSetup

If p.ShowPageSetupDialog Then
  settings = p.Settings
End If

Label1.Text = "PageLeft=" + p.PageLeft.ToString
Label2.Text = "PageTop=" + p.PageTop.ToString
Label3.Text = "PageHeight=" + p.PageHeight.ToString
Label4.Text = "PageWidth=" + p.PageWidth.ToString
Label5.Text = "Height=" + p.Height.ToString
Label6.Text = "Width=" + p.Width.ToString
Label7.Text = "Computed height=" + Str(p.Height - 2 * p.PageTop)
Label8.Text = "Computed width=" + Str(p.Width - 2 * p.PageLeft)

Of course, you need a bunch of Labels (1 to 8) to display the values.

Also, in the XojoExamples folder, seek for the Printing folder to get examples.

To downmload the XojoExamples as zip,
Cmd-N (or Ctrl-N for Windows) to display:
click woith Option Key down) in:

Then click in this button that appeared:=

Expand the zip, Open the folder and search the Printer folder.

Regards

This code:

Var settings As String
Var p As New PrinterSetup

If p.ShowPageSetupDialog Then
  
  // Get the Set up string (Settings)settings = p.Settings
  
// Place here the code to get the Properties you need.
End If

Shows:

Ah! So the difference between those is that one is a text plist and the other is binary. You can call a command line to convert:

From binary to xml

plutil -convert xml1 file.plist

From xml to binary

Plutil-convert binary1 file.plist
(What arnaud said, I didn’t read his whole post)

You don’t need to do anything about the format.

Just store the bytes as is to a file and later load it again. Don’t alter the string and it will just work.

The data inside setup string is not of your concern and can change without notice by the OS.

To be complete…

Simple code and result:

If you need more data than what Xojo provide (look at Xojo Documentation), issue this string quest in Google:

site:developer.apple.com PageFormat

for example. I do not checked, but the Declare library (I forget its name) can be downloaded and checked, depending on the Property/Properties you need to get.

A last information:

look there:

image

You can look there to know if something will fill your needs…

Well, in the end I chose the simplest solution: when the SetupString is not recognized, I ask the user to validate the new one…

Thanks for your replies :slight_smile:

Marc

Does your code work with newly saved SetupStrings?

My suspicion is, that the format of the SetupString changed as noted by your earlier post, and either Xojo, or the API Xojo uses, does not cope with the old format.

If this is the case, I think it is worth figuring out if the change happened in Xojo (i.e. an older version of Xojo is still able to read and use your older printer settings files) or in the OS (i.e. your older print settings files work with the current version of Xojo in an older version of the OS).

In either case it might be worth it to file an issue requesting backward compatibility.

Remark: I cannot test this myself as I do not have access to any MacOS machine. On the other hand I do have experience with messing with the SetupString on Windows, where the whole string is a sequence of text lines of the form Identifier=Value with a binary struct embedded, as defined by the Win32 API, which may vary depending on the operating system version. And there is even a version identifier for the whole thing, so Xojo can provide compatibility if they decide to alter the form of the SetupString

Well, this has already been answered: The setupstring prior to macOS 26 is not read now - #21 by Arnaud_N