Results 1 to 5 of 5

Thread: doc to pdf

  1. #1
    army81 is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default doc to pdf

    Hello guys,
    I need to convert files to pdf doc. Conducting research on the internet I saw that you must use the POI and iText library. Indeed, using this code:

    FileInputStream fis = new FileInputStream(in.getAbsolutePath());
    FileOutputStream fos = new FileOutputStream(out);
    HWPFDocument doc = new HWPFDocument(fis);
    WordExtractor poi = new WordExtractor(doc);
    String[] paragrafi = poi.getParagraphText();
    Document d = new Document();
    PdfWriter.getInstance(d, fos);
    d.open();
    d.newPage();
    for(String paragrafo : paragrafi) {
    d.add(new Paragraph(paragrafo));
    }
    d.close();
    fos.close();
    fis.close();

    I managed to convert but I lose all formatting.
    Does anyone know any tutorial or manual clear to make this conversion in full?
    Thanks

  2. #2
    gafa's Avatar
    gafa is offline Senior Member
    Join Date
    Jun 2010
    Posts
    107
    Rep Power
    0

    Default

    do you need a code?

    But you can simply use OpenOffice for this :)

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by army81 View Post
    Hello guys,
    I need to convert files to pdf doc. Conducting research on the internet I saw that you must use the POI and iText library. Indeed, using this code:

    FileInputStream fis = new FileInputStream(in.getAbsolutePath());
    FileOutputStream fos = new FileOutputStream(out);
    HWPFDocument doc = new HWPFDocument(fis);
    WordExtractor poi = new WordExtractor(doc);
    String[] paragrafi = poi.getParagraphText();
    Document d = new Document();
    PdfWriter.getInstance(d, fos);
    d.open();
    d.newPage();
    for(String paragrafo : paragrafi) {
    d.add(new Paragraph(paragrafo));
    }
    d.close();
    fos.close();
    fis.close();

    I managed to convert but I lose all formatting.
    Does anyone know any tutorial or manual clear to make this conversion in full?
    Thanks
    Because the "formatting" is contained the StyleSheet of the Word doc. Have you even tried to read/use that?

  4. #4
    army81 is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    I tried to use the stylesheet for paragraphs but I can not get it to work.
    I would simply recall the character and alignment of each
    single paragraph. You can send me a sample code?
    Thanks

  5. #5
    rkumar is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default

    Instead of word document try to prepare a html(use your stylesheets) and convert the html file into pdf using w3c Tidy and iText API.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •