B4J Question Printing with jFX8

Peter Lewis

Active Member
Licensed User
Longtime User
Hi

I have made a panel with a Canvas (Holds the Barcode and Lable holds the Barcode Number.

I tried to print the panel but it comes out blank.

I printed the Canvas and it just prints the barcode.

How can I use this Lib to print both as seen below on the screen or is this not possible.

Thanks

barcodedia.png
 

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi!

If it is just exactly what the screen shows, you can use the snapshot method of every view.

B4X:
    Dim m As Image = MainForm.RootPane.Snapshot
   
'Something like this: 
    Dim cv As Canvas
    cv.Initialize("")
    cv.DrawImage(m,0,0,800,600)

And now, you can print the canvas containing the whole image.

If what you want to show is something different, for example, the whole table (not just what its showing) or without buttons or menu, i would recommend creating a pdf and print it.
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
Hi!

If it is just exactly what the screen shows, you can use the snapshot method of every view.

B4X:
    Dim m As Image = MainForm.RootPane.Snapshot
  
'Something like this:
    Dim cv As Canvas
    cv.Initialize("")
    cv.DrawImage(m,0,0,800,600)

And now, you can print the canvas containing the whole image.

If what you want to show is something different, for example, the whole table (not just what its showing) or without buttons or menu, i would recommend creating a pdf and print it.


On the bottom right in a Seperate Pane is the Barcode on a canvas, the text is a label with the parent being the pane
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
If you are using this library https://www.b4x.com/android/forum/threads/b4j-print-javafx8.49836/, then there is no reason it should not work. I have just tested adding a canvas and a label to a pane, printing the pane prints both of them. Can you post some code that doesn;t work and I'll take a look.

The Panel always prints BLANK. I also thought that would be the best way to go, put everything on the pane and print the pane.

Here is the code...Thanks

B4X:
Sub btnPrint_MouseClicked (EventData As MouseEvent)
    Dim P As Printer = Printer_Static.GetDefaultPrinter
    Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(P)
    PJ.PrintPage(Canvas1)
    PJ.PrintPage(Pane1)
    PJ.EndJob
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If I remember correctly, although you are printing a pane, for some reason it still puts it on the page relative to the Main Form.

As a test try moving the pane to 0,0 on the main form. If that works, it may be simpler to create a new form and render anything that needs to be printed to that in the correct places.
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
testprint.png
If I remember correctly, although you are printing a pane, for some reason it still puts it on the page relative to the Main Form.

As a test try moving the pane to 0,0 on the main form. If that works, it may be simpler to create a new form and render anything that needs to be printed to that in the correct places.


I moved it and it printed correctly, Just need to hide the bounding boxesView attachment 55806
 
Last edited:
Upvote 0
Top