PDFBox for pdf processing in android

I try to use pdfbox lib in my android application but I get

java.lang.NoClassDefFoundError: org.pdfbox.pdmodel.PDDocument 

this mistake. I am developing a commercial application, I can not use another Lib like itext. So my question is whether we can use PDfBox in android.

here is my code: -

 PDFParser parser = null; String parsedText = null; PDFTextStripper pdfStripper; PDDocument pdDoc = null; COSDocument cosDoc = null; PDDocumentInformation pdDocInfo; try { f =new File(Environment.getExternalStorageDirectory()+File.separator+"Download"+File.separator+"Services.pdf"); if(f.exists()){ System.out.println("---------exists-----------"); }else{ System.out.println("------NOT----exists----------"); } parser = new PDFParser(new FileInputStream(f)); } catch (Exception e) { System.out.println("Unable to open PDF Parser."); System.out.println("-----------------------error|"+e.toString()); } try { parser.parse(); cosDoc = parser.getDocument(); pdfStripper = new PDFTextStripper(); pdDoc = new PDDocument(cosDoc);//here i'm getting exception //pdDoc = PDDocument.load(f, false); parsedText = pdfStripper.getText(pdDoc); } catch (Exception e) { System.out.println("-----------------------error|"+e.toString()); System.out.println("An exception occured in parsing the PDF Document."); e.printStackTrace(); try { if (cosDoc != null) cosDoc.close(); if (pdDoc != null) pdDoc.close(); } catch (Exception e1) { e.printStackTrace(); } } System.out.println("Done."); System.out.println("-----------------------parsedText|"+parsedText); 

using PDFBox 0.7.3 jar

+2
android pdfbox
Mar 14 2018-12-12T00:
source share
3 answers

The PDFBox seems to depend on the awt and swing classes, which are not available on Android devices.

Therefore, you cannot use PDFBox on Android.

+2
Jun 22 '12 at 13:19
source share

NoClassDefFoundError is raised when the JVM cannot load the class.
As javadoc says
Did you include the pdfbox library on the classpath at compile time?

0
Apr 10 2018-12-12T00:
source share

If you need to extract text from a PDF document on Android, then use https://github.com/RatheeshRavindran/PDFBoxLight I recently ported PDFBox to Android, but keep in mind that this is still in beta.

0
Jun 06 '14 at 4:06
source share



All Articles