Properties while Printing Report

Hi there! I’m tryng to set a few properties while printing my report that is generated by a mysql table.

Having a pleasant headache trying to understand why there’s no a method to pass simple settings like margins and page width / height dynamically.

May be perhaps somebody who can help me understanding if there’s a way to make a settings string working?

Thanks

Var ps As New PrinterSetup
Var document As New PrintDocument // As Report from mySQL

Dim Settings As String
Dim SetupString As MemoryBlock

ps.Landscape = True
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300

If ps.ShowPageSetupDialog Then
  
  Var g As Graphics
  g = OpenPrinterDialog(ps)
  
  If g <> Nil Then
    
    If document.Run(ProjectsTable, ps) Then
      
      If document.Document <> Nil Then
        
        document.Document.Print(g)
        
      End If
      
    End If
    
  End If
  
End If

Did you read the Printer Setup page lately ?

I see PageLeft, PageTop, PageWidth, PageHeight

and
Left, Top, Width, Height.

Aren’t they enough to achieve what you want ?
Whith these, you are able to compute your margins… IMHO

The real question is not wich properties to be used :rofl: but how to implement them since it seems Xojo does not allow properties to be directly attributed to PrinterSetup (ps.Property).

So How?

I think I do not really printed data since… 20 years ago !

But YOU print the data.

So, you are in charge to print lines of text (or/and images) in your “page”. So, you may add properties like Margin_Left and attribute it a value, then



// Set the left Margin
Margin_Left = 50 // Left Margin is 50 pixels

// Draw a text (for printing) at Margin_Left + 50…
g.DrawText("Hello World", Margin_Left + 50, 50)

and so on for the other margins.

And if you want to print a block of text (paragraph):
http://documentation.xojo.com/api/graphics/graphics.html#graphics-drawtext
You set the x, y values and compute wrapWidth with PageWidth Value and Margins (Left and Right).

Is this what you’re searching ?

Thank you Emile, actually I’m going to print a listbox I pass through a Report in Xojo, then print that report using document.Document.Print(g), I also looked at the documentation about in Xojo but I cannot find the exact point or even the correct way to interact with g Graphic or even with the document As PrintDocument As Report and to declare w,h,l,t properties.

That said I already tried with document.Document.Print(g, 0, 0) without success.

did you checked the examples in the Example project folder ? There are 5 in the Reporting folder. :grinning:

Yup, unfortunately the examples make no use of properties but p.MaxHorizontalResolution and p. MaxVerticalResolution.