B4J Question print to pdf textarea changes to default background color

le_toubib

Active Member
Licensed User
Longtime User
hi all
i set the textarea background color with CSSUtils.SetBackgroundColor(textarea1, fx.Colors.white) , which works fine on screen ,
but when trying to "print to pdf" of a pane containing this textarea , its background color apears gray.
i would like to keep it white .
i'm using microsoft print to pdf , in the library print javafx8
thx for ur help
 

stevel05

Expert
Licensed User
Longtime User
It would be useful if you could upload an example project showing the issue. As a guess try setting the background of the pane you are printing to the required background colour.
 
Upvote 0

le_toubib

Active Member
Licensed User
Longtime User
It would be useful if you could upload an example project showing the issue. As a guess try setting the background of the pane you are printing to the required background colour.
thank you for reply , great library , the background for the pane is white , all other controls print ok with white backgrounds except textarea .
originally it happened also whith textfields but i fixed it by adding : -fx-background-color: white;
but this didn't work with textarea .
adding these also didn't work :
textarea background color:
                CSSUtils.SetBackgroundColor(ta, fx.Colors.white)
 CSSUtils.SetStyleProperty(ta, "-fx-control-inner-background", "white")
 CSSUtils.SetStyleProperty(ta, "-fx-focus-color", "white")
if there specific css for printing for textarea ? if yes how to add them programmatically?

this is the whole code i'm using , note that when i took a snapshot , textareas where normally with white background. yet still while printing it s gray

take snapshot and then print:
Public Sub Prints(i As Int) As ResumableSub
        'save file and upload it
        For Each n As Node In PanelsforPages(i).GetAllViewsRecursive
            If n Is TextArea Then
                Dim ta As TextArea = n
                CSSUtils.SetBackgroundColor(ta, fx.Colors.white)
                CSSUtils.SetStyleProperty(ta, "-fx-control-inner-background", "white")
                CSSUtils.SetStyleProperty(ta, "-fx-focus-color", "white")
            else If n Is TextField Then
                Dim tf As TextField = n
                CSSUtils.SetBackgroundColor(tf, fx.Colors.White)
            End If
        Next

        Dim fn As String =  "filename" &  "_" & i & ".jpg"
        Dim Out As OutputStream = File.OpenOutput(File.Dirdata("Averroes") & "\foldername\"  , fn,False)
        PanelsforPages(i).Snapshot.WriteToStream(Out)
        Out.Close
        wait for (UploadFile(fn)) Complete (rslts As Object)
        Sleep(10)
        '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''print
        Dim count As Int = 2
    Dim pr As Printer
    pr = Printer_Static.GetDefaultPrinter
    Dim PA As Paper
        PA.Initialize()
        PA = Paper_static.A4
        Dim PL As PageLayout
        PL.Initialize()
        PL = pr.CreatePageLayout2(PA, PageOrientation_Static.PORTRAIT, "HARDWARE_MINIMUM")
        Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob2(pr) 'CreatePrinterJob
        PJ.GetJobSettings.SetCopies(count)
        PJ.GetJobSettings.SetJobName("Job Name")
        PJ.PrintPage2(PL, PanelsforPages(i))
        PJ.EndJob
Return Null
End Sub


thanks for the great support
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I've just added 3 views to a form, the form's background colour is set to white. I get the following output to PDF using Microsoft Print to PDF.

1696361419862.png


I have not done anything with the background of the TextArea and it does not have a different colour.

If you are seeing a different result, can you post an example and I can then look into it.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Or try changing your code to:

B4X:
For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
        If n Is TextArea Then
            CSSUtils.SetBackgroundColor(n, fx.Colors.white)
            Dim Content As Node = n.As(JavaObject).RunMethod("lookup",Array(".content"))
            CSSUtils.SetBackgroundColor(Content, fx.Colors.White)
        
        else If n Is TextField Then
            CSSUtils.SetBackgroundColor(n, fx.Colors.White)
        End If
    Next
 
Upvote 0

le_toubib

Active Member
Licensed User
Longtime User
Or try changing your code to:

B4X:
For Each n As Node In MainForm.RootPane.GetAllViewsRecursive
        If n Is TextArea Then
            CSSUtils.SetBackgroundColor(n, fx.Colors.white)
            Dim Content As Node = n.As(JavaObject).RunMethod("lookup",Array(".content"))
            CSSUtils.SetBackgroundColor(Content, fx.Colors.White)
       
        else If n Is TextField Then
            CSSUtils.SetBackgroundColor(n, fx.Colors.White)
        End If
    Next
thank you again , the above code solved it
 
Upvote 0
Top