Ciao Antonio, seguendo le tue indicazioni ho risolto il problema (non avevo dubbi che tu mi avresti portato sulla “retta via”!!)
Vorrei per sottoporre la soluzione che ho adottato al tuo giudizio, e ti prego di segnalarmi tutto quello che sbagliato o che potrebbe essere sviluppato in altro modo.
Allora: nella mia applicazione c’ una voce in un men che mi permette di salvare le impostazioni della stampante. Questo il codice:
// salvo le impostazioni della stampante
Dim f As FolderItem
Dim strOut As TextOutputStream
Dim ps As New PrinterSetup
#if DebugBuild Then
f = GetLocalFolderItem("")
#else
f = GetFolderItem("")
#endif
f = f.Child("PrinterSettings.txt")
' se il file non esiste lo creo
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.Close
Return True
Exit Function
End If
End If
end if
// errore
Return False
Poich sono 3 le impostazioni che mi servono, ogni volta che il codice di cui sopra genera il file “PrinterSettings.txt” io lo rinomino manualmente, per cui alla fine ho 3 file (PrinterSettings_1.txt, PrinterSettings_2.txt, PrinterSettings_3.txt)
I metodi che eseguono le stampe sanno, ovviamente, quale file utilizzare.
Per stampare eseguo il codice seguente
Dim rpt As Report
Dim RS As RecordSet
Dim ps As new PrinterSetup
rpt = New SchedaColore
RS = oArticolo.ElencoPerSchedaColore(CodArtIni, CodArtFin, DesArtIni, DesArtFin)
' ---------------------------------------------
// carico le impostazioni della stampante
Dim SetupString As String
SetupString = ReadSetupString("PrinterSettings_1.txt")
If SetupString <> "ERRORE" Then
ps.SetupString = SetupString
End If
' ---------------------------------------------
ps.Landscape = False
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300
Dim g As Graphics
' g = OpenPrinterDialog(ps, Nil)
g = OpenPrinter(ps)
If g <> Nil Then
If rpt.Run( RS, ps ) Then 'if the report runs successfully
rpt.Document.Print(g)
End If
End If
Il metodo ReadSetupString esegue il seguente codice:
// carico le impostazioni
Dim f As FolderItem
Dim SetupString As String
Dim strIn As TextInputStream
#if DebugBuild Then
f = GetLocalFolderItem("")
#else
f = GetFolderItem("")
#endif
f = f.Child(SettingsFile)
If f <> Nil Then
If f.Exists Then
strIn = TextInputStream.Open(f)
SetupString = DecodeBase64(strIn.ReadAll)
strIn.Close
Return SetupString
Exit Function
End If
End If
// errore
Return "ERRORE"
Attendo il tuo parere…e grazie ancora!
Nedi