Saving the PrinterSetup Settings

I am wanting to save the PrinterSetup.Settings (string) to a file for later usage. However, when I look at the data in the string, it looks more like “binary” data (in some spots in the “so-called” string) than an actual plain-text string (with readable characters).

Do you know if the TextOutputStream would be the correct way of saving the settings file, or should I use the BinaryStream instead, since it looks binary in some spots?

Thoughts? Thank you!

Use encodeBase64 when saving PrinterSetups, then decodeBase64 when reading back in.

Hi Byron,
I faced the problem this way:

// Saving the Printer Settings

Dim f As FolderItem
Dim strOut As TextOutputStream
Dim ps As New PrinterSetup

f = GetFolderItem("")

f = f.Child("PrinterSettings.txt")
' If the text file does not exist create it!
If f <> Nil Then
  If ps.PageSetupDialog = True Then
    Dim g As Graphics
    g = OpenPrinterDialog(ps, Nil)
    If g <> Nil Then
      strOut = TextOutputStream.Create(f)
      ' strOut.Write(EncodeBase64(ps.SetupString))
      strOut.Write(ps.SetupString)
      
      strOut.Close
      Return True
      Exit Function
    End If
  End If
End If

Then, before printing, I read the printer settings:

ReadSetupString(SettingsFile As String) As String
  // Reading the Printer settings from the text file

  Dim f As FolderItem
  Dim SetupString As String
  Dim strIn As TextInputStream

  f = GetFolderItem("")

  f = f.Child(SettingsFile)

  If f <> Nil Then
    If f.Exists Then
      strIn = TextInputStream.Open(f)
      ' SetupString = DecodeBase64(strIn.ReadAll)
      SetupString = strIn.ReadAll
      strIn.Close
      Return SetupString
      Exit Function
    End If
  End If
End Function

And finally, when I print the report:

Dim ps As New PrinterSetup

// loading the Printer settoings
Dim SetupString As String
SetupString = ReadSetupString("PrinterSettings.txt")      
ps.SetupString = SetupString

Hope this helps you!

PrinterSetup is binary data.
Please use BinaryStream.

Using TextInputStream can cause trouble if line endings don’t match.

Thank you all! Your insights really help a lot… Much appreciated! :slight_smile: