Print without using OpenPrinterDialog , with ps.SetupString

I use xojo for fun.
I want to print without using OpenPrinterDialog.
I can use OpenPrinter, but this will only use the default printer for Windows.
How can I use another printer?
I tried saving the ps.SetupString in a text file but does not work with OpenPrint.
If I use the saved file with OpenPrinterDialog the printer is selected, but this is no good for me, I will not open opendialofprint!!
Sorry for My English…

Dim ps As New PrinterSetup
Dim g As Graphics
Dim Rs As RecordSet
Dim gPrintSettings As String
Dim settings As String
Dim rpt As RepCotizacion
Dim CustID As String
Dim tmpSetupString as MemoryBlock

if rpt <> nil then
rpt.close
Return
end if

rpt = New RepCotizacion 'set the report project item we are going to use to print the report

SqlStr=“Select clientenum,clientname,tipo,sfecha,cotizado,precioventa,medidas From workorders Where cntid =’” + WorkNum + “’”
Rs = DbConn.SQLSelect(SqlStr)
If DbConn.Error then
MsgBox "Error " + DbConn.ErrorMessage
Return
End If

if Rs.RecordCount > 0 then
rpt.LabCotizaNum.Text=Format(val(WorkNum),“0########”)
rpt.LabTipo.Text=Rs.Field(“tipo”).StringValue
rpt.LabFechaCreate.Text=Rs.Field(“sfecha”).StringValue
rpt.LabCotizado.Text=Rs.Field(“cotizado”).StringValue
''rpt.TxtPrice.Text=Format(Rs.Field(“precioventa”).CurrencyValue,"##,##0.00")
rpt.LabNombre.Text=Rs.Field(“clientenum”).StringValue +"#: "+Rs.Field(“clientname”).StringValue
CustID=Rs.Field(“clientenum”).StringValue.Trim
''rpt.TxtJobs.Text=“Medida:”+Rs.Field(“medidas”).StringValue
end if

Settings =“DoNotAlterThis=SetupString.2”_
+EndOfLine+“ActualHorizontalResolution=72”_
+EndOfLine+“ActualVerticalResolution=72”_
+EndOfLine+“MaxHorizontalResolution=600”_
+EndOfLine+“MaxVerticalResolution=600”_
+EndOfLine+“MarginLeft=0”_
+EndOfLine+“MarginRight=0”_
+EndOfLine+“MarginTop=0”_
+EndOfLine+“MarginBottom=0”_
+EndOfLine+“MinMarginLeft=0”_
+EndOfLine+“MinMarginRight=0”_
+EndOfLine+“MinMarginTop=0”_
+EndOfLine+“MinMarginBottom=0”_
+EndOfLine+“PageSetupFlags=4”_
+EndOfLine+“DevModeStructureSizePS=1044”_
+EndOfLine+“DevModeStructurePS=Kyocera KM-1820”

tmpSetupString=new MemoryBlock(lenb(Settings))
ps.SetupString = tmpSetupString

ps.MaxHorizontalResolution =600
ps.MaxVerticalResolution =600

if rs = nil then
beep
MsgBox “No records found to print.”
else
if rs.RecordCount > 0 then
g=OpenPrinterDialog(ps)

  Dim rr As Integer
  Dim rr1 As Integer
  rr=g.width
  rr1=ps.PageWidth
  ''g=OpenPrinterDialog
  rr=(g.width / 8)
  
  If g <> Nil then
    if rpt.Run(rs,ps) then //if the report ran successfully, print it
      rpt.Document.Print(g)
    end if
  end if
  
end if

end if

Rs.Close

Check these links out:

  1. https://forum.xojo.com/5282-get-selected-printer
  2. https://forum.xojo.com/1618-getting-printer-information
  3. http://forums.realsoftware.com/viewtopic.php?t=1332&highlight=printer

my project this is:
’ carico pagestup stampante
Dim stampaf1 As FolderItem = GetFolderItem(“c:\test1\txtst2.txt”)
if stampaf1.Exists = false then
MsgBox " Stampante COMANDA non Settata"
return
end if
Dim stampat1 As TextInputStream = TextInputStream.Open(stampaf1)
dim setstampante as string
Try
stampat1.Encoding = Encodings.MacRoman
setstampante=stampat1.ReadAll
Finally
stampat1.Close
End Try

’ finito di caricare pagesetup stampante

Dim g As graphics
dim i as Integer
dim tx as string
dim tx2 as string
dim tx3 as string
DIM p AS printerSetup
p = NEW PrinterSetup

‘’’ richiama nome sagra e messaggio
dim nomesagra as string
dim messaggio as string

Dim f As FolderItem = GetFolderItem(“c:\ilovesagra\sagra.txt”)
Dim t As TextInputStream = TextInputStream.Open(f)
Try
t.Encoding = Encodings.MacRoman
nomesagra=t.ReadAll
Finally
t.Close
End Try

Dim f2 As FolderItem = GetFolderItem(“c:\ilovesagra\messaggio.txt”)
Dim t2 As TextInputStream = TextInputStream.Open(f2)
Try
t2.Encoding = Encodings.MacRoman
messaggio=t2.ReadAll
Finally
t2.Close
End Try

‘’’ richiama nome sagra e messaggio
P.SetupString = setstampante
g = OpenPrinter§
If g <> Nil Then
‘’’ stampa progressivo
g.Bold = true

bat in this mode my report print only default Windows printer!!