B4J Question HTMLEditorWrapper - Edit HTML

T201016

Active Member
Licensed User
Longtime User
Hello,
I have a question about the text editor from the example: HTMLEditorWrapper
Well, if you want to print the entire text (see: ScreenShot_0.png) on an A4 sheet,
I only get a fragment of the text printout (ScreenShot_1.png).
I checked the printer parameters, but nothing seems to be wrong
setting, such as multi-page 4 in 1 printing.


I print using the function below,
where "PrintOut" is the content of the text to be printed:

PrintToJobRun:
Public Sub PrintToJobRun(Job As Object, PrintOut As String) As ResumableSub
    Dim WebV As B4XView = HTMLEditor1.As(JavaObject).RunMethod("lookup",Array("WebView"))
    If WebV.IsInitialized Then       
'
'        May be needed to hide the caret, I've seen it once or twice on prints
'        PRINTOUT of formatted text in HtmlText. (don't do anything!)
'
        Dim OrigHTML As String = HTMLEditor1.HtmlText
        HTMLEditor1.HtmlText = PrintOut
        
        Dim JS As JavaObject
        JS.InitializeStatic("org.jsoup.Jsoup")
        Dim Doc As JavaObject = JS.RunMethod("parse", Array(HTMLEditor1.HtmlText))
        
        Dim Body As JavaObject = Doc.RunMethod("body",Null)
        Dim PropStr As String = Body.RunMethod("attr",Array("style"))
        Body.RunMethod("attr",Array("style","caret-color:transparent;" & PropStr))
        
        Dim WebE As JavaObject = WebV.As(JavaObject).RunMethodJO("getEngine",Null)
        WebE.RunMethod("print",Array(Job))
        Sleep(50)
'
'        Unhide the caret
'
        HTMLEditor1.HtmlText = OrigHTML
        HERequestFocus
        Return True
    Else
        Return False
    End If
End Sub

Thank you in advance for your help in explaining how to actually print in A4 format, the entire content of the text.
 

Attachments

  • ScreenShot_0.png
    ScreenShot_0.png
    40.6 KB · Views: 230
  • ScreenShot_1.png
    ScreenShot_1.png
    21.9 KB · Views: 220
Solution
Try this one, You'll see the changes I've made to the Initialize_A4 sub.

Basically they are

  • Created a new form to display the preview and a new layout to keep them separate and avoid possible timing issues with resizing the label.
  • Set some padding on the labels to avoid clipping at the right edge of the print.
  • Set the fontsizes in code, probably not needed if you check the layout fontsizes are the same, but it's probably be easier to maintain.
  • Added an option to use the PrintDialog (it made it easier to test so I left it there)
  • Set the label width and height to the reported printable width and height from the printerLayout
  • Removed the wait on the preview form just so it's easier to compare the preview and the...

Magma

Expert
Licensed User
Longtime User
Without using this library.. with little knowledge i have... I think that you must create a table with some pixels width and then into it a column 100% with width <600pixels (<table><tr><td>)...

as i remember an A4 is about 600pixels at 72dpi (screen resolution)

 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
I invoke the function : PrintToJobRun(...)

PrintToJobRun:
            Dim PJ As PrinterJob = PrinterJob_Static.CreatePrinterJob
            Dim JS As JobSettings = PJ.GetJobSettings
            If JobName = "" Then JobName = "New 1"
            JS.SetJobName(JobName)
            If PJ.ShowPageSetupDialog(Null) = False Then
                PJ.CancelJob
                HERequestFocus
                Return False
            End If
            If PJ.ShowPrintDialog(Null) = False Then
                PJ.CancelJob
                HERequestFocus
                Return False
            End If
            Wait For (PrintToJobRun(PJ.GetObject, HTMLEW_Utils.GetHTMLfromClipboard)) Complete (EndJop As Boolean)
            If EndJop = True Then
                xui.Msgbox2Async("File: "&JobName&CRLF&"Successfully spooleded to the printer queue.", "Printer Job","OK","","",Null)
            End If
            If PJ.EndJob = True Then
                Dim myClipBoard As JavaObject
                myClipBoard.InitializeStatic("javafx.scene.input.Clipboard")
                myClipBoard.RunMethodJO("getSystemClipboard",Null).RunMethod("clear",Null)
            End If
 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Without using this library.. with little knowledge i have... I think that you must create a table with some pixels width and then into it a column 100% with width <600pixels (<table><tr><td>)...

as i remember an A4 is about 600pixels at 72dpi (screen resolution)


Thank you very much, I will try your method.
But I want formatted text (what I see on the screen, I want the printer to print me)
Thanks again for your quick response :)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The print to job sub as provided should print the content of the HTMLEditor view. Changing the Editor content in the printtojob sub can cause timing issues as the page has to be loaded before it can be printed. It is difficult to see what you are trying to achieve from the code you have posted.

When I tested it, just adding the code to hide the cursor was OK with the given delays. If you need more help, can you post your project?
 
Upvote 0

T201016

Active Member
Licensed User
Longtime User
The print to job sub as provided should print the content of the HTMLEditor view. Changing the Editor content in the printtojob sub can cause timing issues as the page has to be loaded before it can be printed. It is difficult to see what you are trying to achieve from the code you have posted.

When I tested it, just adding the code to hide the cursor was OK with the given delays. If you need more help, can you post your project?

I welcome you, @stevel05
My goal is to print the content of the HTML editor view on an A4 sheet.
This is done with the button: btnPrints_Click.

Unfortunately, in my project, the printout of the HTML editor view content fits in the first quarter of A4 paper,
as if it were a 4-on-1 multi-page printout. In addition, the rest of the text is sometimes cut off invisible on the printout.

I have attached the sources.
I will be grateful for your help. Regards.

PS. i use in project: bcprov-jdk15on-154

 

Attachments

  • HTMLEditor.zip
    63.5 KB · Views: 149
  • Lib_B4XEncryption.zip
    2.5 KB · Views: 146
  • Lib_ByteConverter.zip
    5.2 KB · Views: 147
  • Lib_CryptoSHA.zip
    3.7 KB · Views: 147
  • Lib_HTMLEditorWrapper.zip
    421.8 KB · Views: 149
  • Lib_JFXPrintLib0-7.zip
    26.3 KB · Views: 158
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Can you explain more how it should work? When I click the print button I see html code in a new window. If I uncomment the SharedCode.PrintToJob, I get the code printed on an A4Page using a PDF printer.

Unfortunately I can't open the fxml layout files I don't have SceneBuilder installed any more.

It looks as though you are printing the raw HTML, not the rendered output. Is that correct?
 
Last edited:
Upvote 0

T201016

Active Member
Licensed User
Longtime User
Can you explain more how it should work? When I click the print button I see html code in a new window. If I uncomment the SharedCode.PrintToJob, I get the code printed on an A4Page using a PDF printer.

Unfortunately I can't open the fxml layout files I don't have SceneBuilder installed any more.

It looks as though you are printing the raw HTML, not the rendered output. Is that correct?

Hello again.
I tried to explain my steps step by step:


01. STEP0-HTML View Editor.PNG
- I mark the entire content of the text;
- I remember selected text to the cache;
- I click print (btnPrints_Click);
- In the new window I can see the HTML code (STEP1-Print preview.PNG);
- Result from the printer (STEP2-from the Printer.PNG)

02. STEP0-HTML View Editor.PNG
- I mark the entire content of the text;
I DON'T REMEMBER THE SELECTED TEXT FOR THE CACHE;
- I click print (btnPrints_Click);
- In the new window I can see normal text (STEP3-Print preview.PNG);
- Result from the printer (STEP4-from the Printer.PNG)

Progress on 01 and 02 is correct and in line with my expectations.
The only thing that worries me is the results from the printer. Both prints are not arranged
on the entire surface of an A4 sheet. I attached the 01_A4Size.FXML.PNG file
in which the parameters of the "LblTotal" Label, in which I am placing it, are visible
the content of the selected text in an HTML editor.

I have doubts about the correct size of the A4 sheet in the FXML layout,
which I accepted for A4 = 605x870, for Letter = 620x775.
Perhaps they cause such an effect of printouts from the printer (?).

From the Printer.png


Thank you for your interest and help so far
Regards, have a good day.
 

Attachments

  • 01_A4Size.FXML.png
    01_A4Size.FXML.png
    49.2 KB · Views: 157
  • STEP0-HTML View Editor.png
    STEP0-HTML View Editor.png
    42.9 KB · Views: 143
  • STEP1-Print preview.png
    STEP1-Print preview.png
    73.3 KB · Views: 154
  • STEP2-from the Printer.png
    STEP2-from the Printer.png
    477.7 KB · Views: 148
  • STEP3-Print preview.png
    STEP3-Print preview.png
    14.5 KB · Views: 154
  • STEP4-from the Printer.png
    STEP4-from the Printer.png
    423.7 KB · Views: 154
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have you tried switching the paper from landscape to portrait in the Printer dialog?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I will add that the laptop screen is
resolution: 1366x768. Does it matter?
No, you are not printing the whole screen. Just the view which you have set the size of in the layout.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This is what I get printing to a pdf.
 

Attachments

  • test.pdf
    104.3 KB · Views: 219
Upvote 0

T201016

Active Member
Licensed User
Longtime User
No, you are not printing the whole screen. Just the view which you have set the size of in the layout.
So in the FXML system I have to specify different proportions? I'll work on it. I will let you know when something comes out. Thanks :)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Do not use the FXML layout, create a new bjl layout with the Designer with a label of the same dimensions, Just don't anchor it to width or height.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Not really as the size then wouldn't be A4. You probably need to change the wrapping or the padding.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You also need to bear in mind that although the A4 page size is 605 x 870 pixels, the printer will have a margin in which you can't print, so you will need to reduce the layout size to take account of these, or adjust it once the layout is loaded.
 
Upvote 0
Top