B4J Question [Solved] Calling External Jar - How?

Harris

Expert
Licensed User
Longtime User
' Project Attributes - added...
#AdditionalJar: rtf-To-html-1.0.0

I need to call this jar to return a formatted HTML by passing it a RTF string to convert.
I think it is a simple jar - pass it a RTF string and it will return a HTML string....
(I want to show the result in a ABMEditor - Squire sourced...).

I expect I will need to use JavaObject, but don't know what to do next....

This is the source of the jar:

I got the jar from:

Is this the way or some other method?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
#AdditionalJar: rtf-to-html-1.0.0.jar
Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    Log(ConvertRTF("ewfjklw efj wklef "))
End Sub

Sub ConvertRTF (rtf As String) As String
    Dim jo As JavaObject
    jo = jo.InitializeStatic("org.bbottema.rtftohtml.impl.RTF2HTMLConverterClassic").GetField("INSTANCE")
    Return jo.RunMethod("rtf2html", Array(rtf))
End Sub
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Thanks, I shall let you know the outcome!
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Works great!

Proving once again that everything is possible using B4X with guidance from the experts...

B4X:
Sub ConvertRTF (rtf As String) As String
    
    Dim htmltext As String = "None"
    Log(" running rtf - html convert")
    
    Try
        Dim jo As JavaObject
        jo = jo.InitializeStatic("org.bbottema.rtftohtml.impl.RTF2HTMLConverterClassic").GetField("INSTANCE")

        '   these also work - with various results...
        '    jo = jo.InitializeStatic("org.bbottema.rtftohtml.impl.RTF2HTMLConverterJEditorPane").GetField("INSTANCE")
        '    jo = jo.InitializeStatic("org.bbottema.rtftohtml.impl.RTF2HTMLConverterRFCCompliant").GetField("INSTANCE")

        htmltext =  jo.RunMethod("rtf2html", Array(rtf))
    Catch
       Log(" error rtf convert: "&LastException.Message)   
    End Try
    Return htmltext
        
End Sub
 
Upvote 0
Top