Doc To PDF Converter in Android Code

vishal.er07

New member
Mar 13, 2012
0
0
0
:'(
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
 
Guys this problem has been solved..But now I am getting another problem..I am able to convert only text..I need the code sample which can read image from .doc file & write that into pdf file..

Anyone who has any idea is most welcomed...

Thanks in advance
 
Hi, if you'd be kind enough to share your "doc to pdf converter" android studio project? So, I could try resolving my problems on my project. I'm also working on a similar project like this and I'm new in android developing. I'd be very grateful to you if you do this favor.
 
Last edited by a moderator: