Hi all,
i have this library ( Library Compilation B4A )
It is compiled without any problems.
When i try the same then i get this error:
If i open the jar library i see this method ( parsePdf), and if move the code from class to Main activity, this work without problem. So where i wrong ??
The code Class is:
The Code Activity that recall this class is:
The JAR file is itextpdf-5-5-6.jar ( click on for download )
In attachment Project.
Thank you
i have this library ( Library Compilation B4A )
It is compiled without any problems.
When i try the same then i get this error:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
AssetsDir
/storage/emulated/0
main_activity_create (java line: 344)
java.lang.RuntimeException: Method: parsePdf not found in: b4a.example.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
at library.pdftotext.pdftotext._converti(pdftotext.java:62)
at b4a.example.main._activity_create(main.java:344)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
If i open the jar library i see this method ( parsePdf), and if move the code from class to Main activity, this work without problem. So where i wrong ??
The code Class is:
B4X:
#Event: OnMessage
'#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.InitializeContext
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;
public void parsePdf(String filepdf, String filetxt, String nomeevento) throws IOException {
String pdf = filepdf;
String txt = filetxt;
String EventName = nomeevento;
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";
try {
BA ba = (BA) this.getClass().getField("processBA").get(null);
if(ba.subExists(EventName.toLowerCase(BA.cul) + "_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
The Code Activity that recall this class is:
B4X:
#Region Module Attributes
#CanInstallToExternalStorage: False
#LibraryAuthor: Devil-App
#LibraryName: PdfToTxtB4
#LibraryVersion: 1.00
#End Region
#AdditionalJar: itextpdf-5.5.6
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
'Dim nativeMe As JavaObject
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
End Sub
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
Log("OK")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
The JAR file is itextpdf-5-5-6.jar ( click on for download )
In attachment Project.
Thank you