B4J Question Canceling JavaFX8 Print Job

MarcTG

Active Member
Licensed User
Can a job sent to printer be canceled if the user presses cancel in the print/setup dialog? I've noticed that with the code bellow, pressing cancel does not cancel the print job, it still sends it to the printer:

B4X:
    Dim p As Printer
    p.Initialize
    Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob
    Dim JS As JobSettings = PJ.GetJobSettings
JS.SetJobName("Test print")
    PJ.ShowPageSetupDialog(Null)
    PJ.ShowPrintDialog(Null)
    PJ.PrintPage(ScaleOutput(PJ.GetPrinter,MainForm.RootPane))
    PJ.EndJob
 

stevel05

Expert
Licensed User
Both PJ.ShowPageSetupDialog(Null) and PJ.ShowPrintDialog(Null) return a boolean value which is False if Cancel was pressed and True otherwise.
 

MarcTG

Active Member
Licensed User
Thanks! I added:
B4X:
If PJ.ShowPageSetupDialog(Null)=False Or PJ.ShowPrintDialog(Null)=False Then
        PJ.CancelJob
    End If
before printpage.
 
Top