Here simple code library in Eclipse: :signOops:
Use only file itextpdf-5.3.3.jar
Here simple code in B4A... :signOops:
Here simple code project in Eclipse Works: :sign0098:
Use only file itextpdf-5.3.3.jar
Download iTextpdf library .jar here...
Select a mirror
Create folder lib and add itextpdf-5.3.3.jar
I'm not a good programmer Eclipse. :sign0013:
Error in LogCat:
Use only file itextpdf-5.3.3.jar
PHP:
package com.digitline.txtofpdf;
import java.io.IOException;
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.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@ShortName("TXTofPDF")
@Version(1)
//@DependsOn(values = {"itextpdf-5.3.3.jar"})
public class TXTofPDF {
//Extract text of pdf in page
public String readTextForPDF(String pdfFile, Integer page) throws IOException {
PdfReader reader = new PdfReader(pdfFile);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
TextExtractionStrategy strategy;
strategy = parser.processContent(page, new SimpleTextExtractionStrategy());
reader.close();
return strategy.getResultantText();
}
}
Here simple code in B4A... :signOops:
B4X:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
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.
Dim extractTXT As TXTofPDF
Dim EditText1 As EditText
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")
EditText1.Text = extractTXT.readTextForPDF("/mnt/extsd/aula.pdf", 7)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Here simple code project in Eclipse Works: :sign0098:
Use only file itextpdf-5.3.3.jar
PHP:
package com.example.exttxtofpdf;
import java.io.IOException;
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 android.os.Bundle;
import android.widget.EditText;
import android.app.Activity;
public class MainActivity extends Activity {
/** The original PDF that will be parsed. */
public static final String PREFACE = "/mnt/extsd/aula.pdf";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
this.parsePdf(PREFACE, 7);
} catch(Exception e) {
System.out.println("Error loading pdf" + e);
}
}
public void parsePdf(String pdf, Integer page) throws IOException {
PdfReader reader = new PdfReader(pdf);
PdfReaderContentParser parser = new PdfReaderContentParser(reader);
TextExtractionStrategy strategy;
strategy = parser.processContent(page, new SimpleTextExtractionStrategy());
reader.close();
EditText text1 = (EditText) findViewById(R.id.editText1);
text1.setText(strategy.getResultantText());
}
}
Download iTextpdf library .jar here...
Select a mirror
Create folder lib and add itextpdf-5.3.3.jar
I'm not a good programmer Eclipse. :sign0013:
Error in LogCat:
LogCat connected to: 192.168.1.10:5555
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:21)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:21)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:21)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:21)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:20)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:20)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 234)
java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:20)
at digitline.txtofpdf.main._activity_create(main.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 237)
java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:20)
at digitline.txtofpdf.main._activity_create(main.java:237)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 237)
java.lang.NoClassDefFoundError: com.itextpdf.text.pdf.PdfReader
at com.digitline.txtofpdf.TXTofPDF.readTextForPDF(TXTofPDF.java:20)
at digitline.txtofpdf.main._activity_create(main.java:237)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at digitline.txtofpdf.main.afterFirstLayout(main.java:89)
at digitline.txtofpdf.main.access$100(main.java:16)
at digitline.txtofpdf.main$WaitForLayout.run(main.java:74)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)