1. Check out our companion app, Forums for Android! Download from Google Play

Doc To PDF Converter in Android Code

Discussion in 'Application Development' started by vishal07, Mar 13, 2012.

  1. vishal07

    vishal07 New Member
    Thread Starter
    5

    Mar 13, 2012
    1
    0
    5
    Hello Guys,
    I am making an application in which I need to convert selected .doc file into .pdf file..I am not getting why I am geeting the error which I have mentioned below.I am using iText 5.1.1 to do file operations related to .doc & .pdf..Any single help/hint will be appreciated..Thanks in advance..
    This is my code of onClick() event for "Convert" button::

    String[] paragraphs = null;

    //Color clr=new Color();
    try {


    POIFSFileSystem fs = null;
    try {


    InputStream is = new FileInputStream(
    "/sdcard/Spring.doc");

    WordExtractor we = new WordExtractor(is);

    paragraphs = we.getParagraphText();

    System.out.println("Word Document has " + paragraphs.length
    + " paragraphs");
    for (int i = 0; i < paragraphs.length; i++) {
    paragraphs = paragraphs.replaceAll("\\cM?\r?\n",
    "");
    System.out.println("Length:" + paragraphs.length());
    }
    } catch (Exception e) {
    e.printStackTrace();
    }



    Document document = new Document(PageSize.A4, 36, 72, 108, 180);
    PdfWriter.getInstance(document, new FileOutputStream(
    "/sdcard/pdfFile.pdf"));
    document.open();

    System.out.println("Text is inserted into pdf file");
    document.close();
    } catch (Exception e) {
    }

    ==========================================================
    This is my imports which I have used ::

    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;

    import org.apache.poi.hwpf.extractor.WordExtractor;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;


    import android.graphics.*;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;

    import com.action.R;
    import com.lowagie.text.Document;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.pdf.PdfWriter;
    ==========================================================

    And the error I am geeting is ::


    E/dalvikvm(3192): Could not find class 'com.lowagie.text.pdf.ExtendedColor', referenced from method com.lowagie.text.pdf.PdfWriter.checkPDFXConformance
    E/dalvikvm(3192): Could not find class 'java.awt.Color', referenced from method com.lowagie.text.pdf.PdfDocument.writeLineToContent
    E/dalvikvm(3192): Could not find class 'com.lowagie.text.pdf.PdfGraphics2D', referenced from method com.lowagie.text.pdf.PdfContentByte.createGraphics
    E/dalvikvm(3192): Could not find class 'com.lowagie.text.pdf.PdfPrinterGraphics2D', referenced from method com.lowagie.text.pdf.PdfContentByte.createPrinterGraphics
     

    Advertisement

  2. Unforgiven

    Unforgiven -.. --- - / -.. .- ... ....
    Moderator
    4,238

    Jun 23, 2010
    33,219
    32,562
    4,238
    Male
    Douglas, MA
    I've moved this thread to Application Development so it gets the right eyeballs on it.:)
     

Share This Page

Loading...