Inserer une image à un ".doc" en java

Résolu
Bonjour à tous,
je veux créer un document word (.doc ou .docx) qui contient des images,
j'ai ce code qui permet d'ajouter du texte au document word et il marche très bien, mais je ne sais pas comment faire pour ajouter l'image, j'ai cherché sur le site d'apache POI mais j'ai pas trouve ce que je cherche, svp quelqu'un peut m'aider??

private static void writeToFile(String content, String path) {
try{
POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();
directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
FileOutputStream out = new FileOutputStream(path);

fs.writeFilesystem(out);
out.close();
}
catch(Exception ex){
System.out.println(ex.getMessage());
}
}
}


3 réponses

  1. en fin j'ai trouvé la solution, voici le code pour ceux qui s'intéressent:

    RtfWriter2.getInstance(document,	new FileOutputStream("file.doc"));
    document.open();
    Image image = Image.getInstance ("01.JPG");
    Paragraph para=new Paragraph("RoseIndia.net  is a global services company that ensures ");
    
    document.add(para); 
    document.add(image); 
    document.close();
    
    


    vous devez télécharger ce jar et l'ajouter à votre projet
    http://www.java2s.com/Code/Jar/GHI/DownloadiTextrtf210jar.htm