Hi all i have this code in my class ( this is a library write in B4A ):
Class pdftotext:
i have this code in Activity Main:
All work but event dont fire. When i run app i have this in my log:
so The name event is pdf_onmessage and in activity i have this sub.
The JAR file is itextpdf-5-5-6.jar ( click on for download )
In attachment project
Any Suggestion ?
Thank you
Class pdftotext:
B4X:
#Event: onMessage(Success As String )
'#Event: OnSecond
Private Sub Class_Globals
Private nativeMe As JavaObject
Private nome_evento As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(evento As String)
nome_evento = evento
End Sub
Public Sub Converti(namefilepdf As String, namefiletxt As String)
' Log(File.DirAssets)
' Log(File.DirRootExternal)
nativeMe = Me
Dim filepdf As String = namefilepdf
Dim filetxt As String = namefiletxt
nativeMe.RunMethod("parsePdf", Array(filepdf, filetxt, nome_evento))
End Sub
#If Java
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.TextExtractionStrategy;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.*;
private BA ba;
private String eventName;
public void parsePdf(String filepdf, String filetxt, String nomeevento) throws IOException {
String pdf = filepdf;
String txt = filetxt;
this.eventName = nomeevento.toLowerCase(BA.cul);
PdfReader reader = new PdfReader(pdf);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
PrintWriter out = new PrintWriter(new FileOutputStream(txt));
TextExtractionStrategy strategy;
for (int i = 1; i <= reader.getNumberOfPages(); i++) {
strategy = parser.processContent(i, new SimpleTextExtractionStrategy());
out.println(strategy.getResultantText());
}
reader.close();
out.flush();
out.close();
String Convertito = "Done";
BA.Log("Name Event: " + eventName + "_onmessage");
try {
if(ba.subExists(eventName + "_onmessage")){
BA.Log("Found");
ba.raiseEventFromUI(this, eventName.toLowerCase(BA.cul) + "_onmessage", Convertito);
} else {
BA.Log("Not Found");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
#End If
i have this code in Activity Main:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Dim filepdf As String = File.DirRootExternal &"/test-armen.pdf"
Dim filetxt As String = File.DirRootExternal &"/test.txt"
Dim pdf As pdftotext
pdf.Initialize("pdf")
pdf.Converti(filepdf, filetxt)
End Sub
Sub pdf_onMessage(Success As String )
Log("Convertion: " & Success)
End Sub
All work but event dont fire. When i run app i have this in my log:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Name Event: pdf_onmessage
Not Found
** Activity (main) Resume **
so The name event is pdf_onmessage and in activity i have this sub.
The JAR file is itextpdf-5-5-6.jar ( click on for download )
In attachment project
Any Suggestion ?
Thank you