Doc To PDF Converter in Android Code

Last Updated:

  1. vishal07

    vishal07 New Member

    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(

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

    Document document = new Document(PageSize.A4, 36, 72, 108, 180);
    PdfWriter.getInstance(document, new FileOutputStream(

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

    This is my imports which I have used ::


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

    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

  2. Unforgiven

    Unforgiven -.. --- - / -.. .- ... .... Moderator

    I've moved this thread to Application Development so it gets the right eyeballs on it.:)

Share This Page