2012-03-14 27 views
2

我想使用PDFBOX lib放到我的Android应用程序处理的PDF,但即时得到PDFBox的在Android电子

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

此错误。至于我正在开发的商业应用程序我不能使用其他库像iText的。所以我的问题是我们可以在android中使用PDfBox。

这里是我的代码: - 使用PDFBox的0.7.3罐子当JVM不能加载类

+0

我们可以看到你的代码.... – 2012-03-14 07:43:38

+0

@Vincent我已经发布的代码只是检查 – Prachi 2012-03-14 08:20:44

回答

0

NoClassDefFoundError的抛出

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); 


As the javadoc says
编译期间,您是否在类路径中包含pdfbox库?

+0

@Shyda是的,我已经包括PDFBOX lib中,但仍没有运气... – Prachi 2012-04-11 10:47:28

+0

@curious_mind参见[这个问题](HTTP:/ /stackoverflow.com/questions/8980668/how-to-add-pdfbox-to-an-android-project)。这是同样的错误吗? – Shyba 2012-04-11 16:56:58

2

似乎PDFBox取决于Android设备上不可用的awt和swing类。

因此,您无法在Android上使用PDFBox。