1

I am generating a pdf document using itext in my app. I made sure to download the android version from the site.

When I run the app in the emulator (without connecting the phone), generate the document and pull it from the SD card in eclipse using "Pull from device", everything works fine. When i installed (sideloaded) the app onto a phone and generated the pdf from the phone, the app showed a success message and created the document in the SD card. I have also clicked on order and export when building the path.

My problem is that when i create the document on the phone the following errors when i try to open it with Adobe Reader "The document is empty (size 0KB). I don't know what goes wrong on the phone because in the emulator(without connecting the phone) it works fine. I have added the jar to the build path and libs folder. I've browsed the internet for solutions but couldn't find one. Maybe it has something to do with my classpath. I'm using iText.Here's my code for my classpath:

<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="lib" path="libs/itextpdf-5.3.4.jar"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

Here's my code to generate the pdf:

public void createPDF(String title, String summary, String overview, String marketing, String mgmt, 
          String assets, String financial) {
      String filePath = file + ".pdf";
    try {
      Document document=new Document();

      File root = new File(Environment.getExternalStorageDirectory(), "Plans");
        if (!root.exists()) {
                root.mkdirs();
                }

      File path = new File(root, filePath);         
      PdfWriter.getInstance(document,new FileOutputStream(path));      
      document.open();

      addMetaData(document); //methods i created for the layout of the document
      addTitlePage(document, title);
      addSummary(document, summary);
      addOverview(document, overview);
      addAssets(document, assets);
      addMarketing(document, marketing);
      addManagement(document, mgmt);     
      addFinancial(document, financial);

      document.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  • You'll have to share the stack trace. You'll probably see a ClassNotFoundException because you didn't package iText with your APK, but that's a wild guess. You shouldn't expect an answer if you don't add extra info to your question. – Bruno Lowagie Sep 10 '13 at 10:37
  • Furthermore: you're using the Java iText instead of iTextG: http://sourceforge.net/projects/itextg (I know because the jar you use is itextpdf-5.3.4.jar instead of itextg-5.3.4.jar) – Bruno Lowagie Sep 10 '13 at 10:37

0 Answers0