I just quickly modified code that I found on internet

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.hwpf.extractor.WordExtractor;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class GeneratePDF {

    public static void main(String[] args) {
        String pdfPath = "C:/";
        String pdfDocPath = null;
        try {
            InputStream is = new BufferedInputStream(new FileInputStream("C:/Test.doc"));
            WordExtractor wd = new WordExtractor(is);
            String text = wd.getText();
            Document document = new Document();
            PdfWriter.getInstance(document, new FileOutputStream(pdfPath + "viewDoc.pdf"));
            document.open();
            document.add(new Paragraph(text));
            document.close();
            pdfDocPath = pdfPath + "viewDoc.pdf";
            System.out.println("Pdf document path is" + pdfDocPath);
        }
        catch (FileNotFoundException e1) {
            System.out.println("File does not exist.");
        }
        catch (IOException ioe) {
            System.out.println("IO Exception");
        }
        catch (DocumentException e) {
            e.printStackTrace();
        }
    }

}

Just keep in mind POI doesn't like "docx" format yet...

The code is great but it copy just the text.

The pdf doesn´t have the word format and headers :S

The code is great but it copy just the text.

The pdf doesn´t have the word format and headers :S

That would be because we been discussing just simple example how to get POI and iText talking together. It is on everyone who wish to use it to extend the application functionality to get maximum out of it.

can u send me download link for itext/hwpf

thanks inadvance!

hey peter_budo,
where do u get hwpf ?
please help me out

thanks in advance

Hi to all,
I want to convert an MS Word doc (Text,Table and Images) and put those in a html format or place it any specified location.
is it possible?


Please reply................

Everything possible see here

Actually to convert from .doc to .pdf via Java I could not find a direct method, But I found a two step process,
Access your Microsoft Format files using Apache POI, You can read more about it here.
Next use iText to convert the data you have into a PDF.

I know it's an old post, but Stephen, can you be nice and provide an example of how it's done? I need to do exactly that.

lot of discussion has been made by fellows but the problem they still face in professional industry. I can give you best advice and believe me with no cost. You people, specially professionals in IT industry can now convert any kind of file format Convert to and from HTML, DOCX, XLSX, PPTX, PDF and more through only SaasPose. Believe me you can't have a solution against Saaspose.

<Spam deleted>

Madhia: this thread was marked solved three years ago. think the OP is still looking?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.