PDFBox for processing pdf in android
Asked Answered
N

3

2

i am trying to use pdfbox lib into my android app but im getting

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

this error .as i'm developing commercial app i can not use other Lib like itext .So my question is can we 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

Nopar answered 14/3, 2012 at 4:55 Comment(1)
@Vincent i have posted code just check itNopar
A
2

It seems that PDFBox is depending on awt and swing classes that are not available on Android devices.

Therefor you can not use PDFBox on Android.

Azarria answered 22/6, 2012 at 13:19 Comment(0)
F
0

NoClassDefFoundError is thrown when the JVM can't load a class.
As the javadoc says
Have you included the pdfbox library on classpath during compilation?

Fantoccini answered 10/4, 2012 at 21:43 Comment(1)
@curious_mind See this question . Is it the same error?Fantoccini
R
0

If you only need to extract text from PDF document in Android , then use this https://github.com/RatheeshRavindran/PDFBoxLight I recently did the porting of PDFBox to Android but please note that this still in Beta.

Romola answered 6/6, 2014 at 4:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.