1

I have a project steganography to hide docx document into jpeg image. Using apache POI, I can run it and read docx document but only letters can be read.

Even though there are pictures in it.

Here is the code

FileInputStream in = null;
    try
    {
        in = new FileInputStream(directory);
        XWPFDocument datax = new XWPFDocument(in);
        XWPFWordExtractor extract = new XWPFWordExtractor(datax);
        String DataFinal = extract.getText();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        this.isi_file = extract.getText();
    }
    catch (IOException x) {}
        System.out.println("isi :" + this.isi_file);

How can I read all component in the docx document using java? Please help me and thank you for your helping.

3
  • 1
    A docx file, like any other file is a bunch of bytes. When read by the appropriate decoder then you can view the text and images properly. But in terms of hiding the file, just read the file in a byte array. Commented Jun 26, 2018 at 8:31
  • how about the code? Commented Jun 26, 2018 at 10:22
  • What code? To do what I suggested? It's been covered before. Search for how to read a file to a byte array. Commented Jun 26, 2018 at 10:56

1 Answer 1

3

Please check documentation for XWPFDocument class. It contains some useful methods, for example:

In your code snippet exists line XWPFDocument datax = new XWPFDocument(in);. So after that line your can write some code like:

// process all pictures in document
for (XWPFPictureData picture : datax.getAllPictures()) {
    // get each picture as byte array
    byte[] pictureData = picture.getData();
    // process picture somehow
    ...
}
Sign up to request clarification or add additional context in comments.

4 Comments

How can I make it be the code? I dont get the meaning in that documentation.
@Apuranic, I edit my answer and add small code snippet that shows how to process pictures in document. Hope this helps.
@Apuranic, output of what? Please provide concrete code snippet, because my example is incomplete and even would not compile without your modifications.
oh I see, sorry for misunderstanding n thank you for your help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.