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
I invoke the function : 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
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)
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?
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?
No, it is fixed vertically.Have you tried switching the paper from landscape to portrait in the Printer dialog?
No, you are not printing the whole screen. Just the view which you have set the size of in the layout.I will add that the laptop screen is
resolution: 1366x768. Does it matter?
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. ThanksNo, you are not printing the whole screen. Just the view which you have set the size of in the layout.
Yes, indeed a crashed view to the right of the margin. So I should increase the view size ...This is what I get printing to a pdf.
I'll try to do just that. Thanks again for your support.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.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?