Printing Margins. Still an issue

Hey XOJOers… Again!

I’m still on an issue we experience for a Long time already. We want the Printer Margins to be Always set to 0. At this Moment the user Always Needs to set These every time. However, this should never be the case. People here are getting irritated About it. However, we can’t seem to modify it. We succeeded once with the MBS Plugin for printing by editing the string, but we removed this Code already. Funny part: it still keeps printing without any margins at all.

We’re not sure how to handle this. We already have the automatic Printer selection which works fine (Thanks to the MBS Plugin), but the margin is still there. We would love to get rid of this whole Option screen entirely. If we can resolve this issue one of the most heavy weighting Problems for the whole program will be solved, but we’ve been working on it for multiple days now, without any success. I’m working with XOJO for three years now, and still didn’t find a solution that worked, except for mentioned above, but we have no idea how this is working at this Moment, since the Code is kinda the same!

What are our possibilities? Since today we’re running the current Version of Xojo. (2019 Release 3.1). This is how we’re currently printing:

[code]ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300

dim s as WindowsPrinterMBS
dim o as Integer
o = s.SetDefaultPrinter(“LK-DRUCK-TRESEN”)

if o <> 0 then
MsgBox("Problem mit Druckereinstellungen: " + Str(o))
end if

If ps.PageSetupDialog Then

//Druck Einstellungen spreichern:
wndHauptfenster.printsettings = ps.SetupString

Dim g As graphics
g = OpenPrinterDialog(ps, Nil)
If g <> Nil Then

// if the report runs successfully
If rpt.Run( orders, ps ) Then
  
  rpt.Document.Print(g)
End If

End If

End If
[/code]

You will need to save the setupstring to a database then read that saved setupstring the next time you print.

theoretical

@Markus Rauch
Applied
I use that approach quite often. For Windows I even created a custom Printer Dialog. No need to open the Pagesetupdialog every time you print. I just added a button on my custom Printerdialog that opens the Pagesetupdialog if you need to change the margins again.

[quote=495923:@Gary Smith]@Markus Rauch
Applied
I use that approach quite often. For Windows I even created a custom Printer Dialog. No need to open the Pagesetupdialog every time you print. I just added a button on my custom Printerdialog that opens the Pagesetupdialog if you need to change the margins again.[/quote]

Hey.

I’ve tried this and I can’t get it to work. It still opens up the Page Settings Dialog where the margins are incorrectly configured, even when I load the string from the database. Or am I doing it wrong?

what i need for users is the selection once, saved and if the app opens another days it used the same margins.
@Gary Smith
maybe u use a other approach.

[quote=497158:@Herge Lammers]Hey.

I’ve tried this and I can’t get it to work. It still opens up the Page Settings Dialog where the margins are incorrectly configured, even when I load the string from the database. Or am I doing it wrong?

[/quote]

If ps.PageSetupDialog Then // This will open the page setup dialog. Don’t do that. Here is some old code from 1 of the methods that I use. I use MSSQL for the database, You will need to save the SetupString as row.BlobColumn
Let me know if you need to see the other methods that this code is calling.
This method is called with a Print button on my custom printer dialog window. This is for Windows only.

  Dim ps As New PrinterSetup
  Dim s As String
  s = ConvertEncoding(GetDefaultPrinter, Encodings.UTF8)
  Dim sql as string
  Dim rpt As New Report1
  Dim Rs as Recordset
  Dim RsRpt as Recordset
  db = new ODBCDatabase
  db.DataSource="hidden"
  if db.connect then
    If db.error then
      Exit
    Else
      
      //Run a query to get the data for the report
      select case WhichReport
      case "Rpt1"
        if Len(Warehouse) > 0 then
          sql = "SELECT PartsKit.KitNo, PartsKit.PartNo, PartsKit.Qty, PartsKit.Instruction, PartsKit.NoPrint, PartsKit.Required, PartsKit.PmName, Parts.Description, Parts.Warehouse FROM PartsKit LEFT OUTER JOIN Parts ON PartsKit.PartNo = Parts.PartNo WHERE (((PartsKit.KitNo)='" + WinKits.TfKit.text + "') AND ((Parts.Warehouse)='" + warehouse +"' Or (Parts.Warehouse) IS NULL))"
        else
          sql = "SELECT KitNo, PartNo, Qty, Instruction, NoPrint, Required, PmName from PartsKit where KitNo = '" + WinKits.TfKit.text + "'"
        end if
      case "Rpt2"
        sql = "SELECT PmParts.SerialNo, PmParts.PartNo, PmParts.Qty, PmParts.Instruction, PmParts.Required, PmParts.PmName, Parts.Description, Parts.Warehouse FROM PmParts LEFT OUTER JOIN Parts ON PmParts.PartNo = Parts.PartNo WHERE (((PmParts.SerialNo)='" + WnPmParts.Textfield1.Text + "') AND ((Parts.Warehouse)='" + warehouse +"' Or (Parts.Warehouse) IS NULL))"
        rpt.Label20.Text = ""
        rpt.field3.DataField = "SerialNo"
      end select
      // End the sql stuff
      rpt.Label3.text = ""
      
      RsRpt = db.SQLSelect(sql)
      
      If RsRpt = Nil Then
        Beep
        MsgBox("No records found to print.")
      Else
        db2 = new ODBCDatabase
        db2.DataSource="hidden"
        if db2.connect then
          If db2.error then
            Exit
            //call the printersetup then call the openprinter with the printer setup.
          Else
            sql ="SELECT * FROM PrintSetup where Name = '" + Employee +"'and DefPrinter = '" + s + "'"
            rs = db2.SQLSelect(sql)
            if rs <> nil and rs.eof = false then
              //added something here to check if the PrtSetting is empty.
              if rs.field("PrtSetting").StringValue = "" then
                PageSetting
              else
                SetupSettings = rs.Field("PrtSetting").StringValue  //SetupSettings is a property
              end if
              rs.close
            else //No setting found so call PageSetting. It will open the settings dialog and save the printer settings to the database. Then the query can read them from the database. 
              PageSetting
            end if
            ps.SetupString = SetupSettings //SetupSettings is a Property. It is filled from the recordset or when PageSetting is called.
            ps.MaxHorizontalResolution = 300
            ps.MaxVerticalResolution = 300
          end if
        end if
      end if
      //Print the report
      dim I as integer
      Dim g As Graphics
      g = OpenPrinter(ps)
      
      If g <> Nil Then
        if NumCopies > 1 then //Print multiple copies
          If rpt.Run(RsRpt, ps) Then
            For I = 1 to NumCopies
              rpt.Document.Print(g)
              if I < NumCopies then
                g.NextPage
              else
                g = Nil
              end if
            next
          End If
        else
          If rpt.Run(RsRpt, ps) Then //Print 1 copy
            rpt.Document.Print(g)
          End If
        End If
      else
        Msgbox "Printing Canceled"
      end if
    end if
    db.close
  end if

i believe my last intend was to open the PageSetupDialog with the last used margins and for a test i stored this settings in a TextArea. this SetupString was not used for the dialog, means the dialog show something else.

@Markus R
I have never tried to save the setupstring locally in a textarea.
I always save the SetupString to a database with DataType = Image or DataType = varbinary(MAX)
Here is a line from my save code. I even made notes to save as blobColumn because nothing else worked.

row.blobColumn("PrtSetting") = SetupSettings //Must use row.blobColumn for this binary field. This took a while for me to figure out.

The biggest issue with printing in windows is that you need to know which printer you are going to print to, before you get the setupstring. Xojo kinda has it reversed. That is the reason that I made my own customer PrinterDialog. With that, I can select the printer that I want to use, it then gets the setupstring for that printer from my database. If it can’t find one that is saved then the pagesetup dialog is displayed and saves\uses the settings for the selected printer.
Thanks

i tested it again,
in my case i can say that TextArea1 did not work for Settings but String or MemoryBlock as Property is ok. omg.
somehow Xojo treat Strings same as Binary Data.

String has always been just a “bag o bytes”. You can put any binary data in it. TextArea will convert line endings to Mac style, so on Windows, it will mangle the SetupString.

Hey all! ( @Markus Rauch @Gary Smith )

So I find it kinda irritating that it takes multiple months just to print without margins. I think XOJO really overcomplicated this as it’s even easier to print with web tools.

So, i’ve made the following code wich loads the string from the database. The thing is, now the text is like really small everywhere (which wasn’t the case normally). Is anything wrong? I really appreciate your guys help!

[code]Dim druckauftrag As New DruckRechnung
Dim ps As New PrinterSetup
Dim rpt As New report_rechnung

ps.SetupString = storedString

ps.MaxHorizontalResolution = -1
ps.MaxVerticalResolution = -1

g = OpenPrinter(ps)

If rpt.Run(druckauftrag, ps) Then
If rpt.Document <> Nil Then
wndHauptfenster.printsettings = ps.SetupString
rpt.Document.Print(g)
End If
End If[/code]

My setup string is now

DoNotAlterThis=SetupString.2 ActualHorizontalResolution=600 ActualVerticalResolution=600 MaxHorizontalResolution=-1 MaxVerticalResolution=-1 MinMarginLeft=0 MinMarginRight=0 MinMarginTop=0 MinMarginBottom=0 PageSetupFlags=8 DevModeStructureSizePS=1348 DevModeStructurePS=L

you printed with 300 dpi before?

Yes!

you could try to use 300 not -1 here

Max...Resolution = -1

or with higher dpi i think you need to edit your report page if the text is so small to read.