B4J Library Applies to JFX8Print How can you set the print margins

Applies to JFX8Print How can you set the print margins without using the ShowPageSetupDialog.
JFX8Print always prints with a margin. I want to set the margin to 0.

I don't find the possibility to adjust the border anywhere.
 

stevel05

Expert
Licensed User
Longtime User
You can use one of the CreatePageLayout methods of the Printer Class then call GetJobSettings.SetPageLayout on the printer job. If I remember correctly I don't think you can set the margins to 0, you might get an error. You may have to be set them to 1 or a small number.
 

Peter128

Member
Licensed User
Longtime User
Yes, that sounds good. I just haven't made it yet. Can you give a small example of how to do it. Thank you very much.
 

stevel05

Expert
Licensed User
Longtime User
Try this:
B4X:
'    'Print without dialogs

    'just to find available printers then select manually
    Dim L As List = Printer_Static.GetAllPrinters
    For Each P As Printer In L
        Log(P.GetName)
    Next

    Dim P As Printer = GetPrinter("Microsoft Print to PDF") 'Change to an available printer
    If P <> Null And P.IsInitialized Then
        Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(P)
     
        Dim Layout As PageLayout = P.CreatePageLayout(Paper_static.A4,PageOrientation_Static.PORTRAIT,0,0,0,0)
        PJ.GetJobSettings.SetPageLayout(Layout)
        PJ.PrintPage(Pane1)
        PJ.EndJob
        Log("Print Done")
    Else
        Log("Printer not found")
    End If

It appears that you can set the margins to 0 manually, but not with the dialogs. This may depend on the printer.
 
Last edited:

Peter128

Member
Licensed User
Longtime User
Thank you so much Steve. Nevertheless, I always had an error message with "P.CreatePageLayout". Then I found an example at William Lancee that finally helped me. Below is my complete code. Thanks again.

' Drucken über FX8 ----------------------------------------------
Dim PrList As List = Printer_Static.GetAllPrinters
For Each Pr As Printer In PrList
' Log(Pr.GetName)
If Pr.GetName.StartsWith(DRucken.druckername) Then Exit 'printer name is any string variable - printer name
Next
Ausdruckform.Druckbon.Text=Druckbon 'any text
Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(Pr)
Private PL As PageLayout = Pr.CreatePageLayout(Pr.GetPrinterAttributes.GetDefaultPaper, PageOrientation_Static.PORTRAIT, 0.5, 0.5, 0.5, 0.5)
PJ.GetJobSettings.SetPageLayout(PL)
'PJ.ShowPageSetupDialog(Null)
PJ.PrintPage(Ausdruckform.Druckbon)
PJ.EndJob
'-------------------------------------------------------------------
 
Top