This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Graphics and word documents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Graphics and word documents" Watch "Graphics and word documents" New topic

Graphics and word documents

Michael Helgens

Joined: Jun 18, 2009
Posts: 1

So I've got this stack of code that sorts through a text file and writes all of the things neatly just how I want them into a word document for printing. The only trouble is that I would like to include an image at the top of the word document which I have stored in a .png or .jpg file as needed. Is there a way to get Java to put the image(s) at the top of the page before writing the rest of the document?

Thanks, in advance, for your help,

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

Had you tried taking the image as a bit stream and writing at the start of word document ?

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
Welcome to JavaRanch.

Word documents are structured file formats; simply prepending binary image data to them is not going to work.

The common Java API for working with doc files is Apache POI, and it doesn't yet support adding images (although it can extract existing images just fine). A workaround (or hack, depending on your point of view) is described here. In particular, in the messages by Rainer Schwarze of Oct 11 and Oct 15.
I agree. Here's the link:
subject: Graphics and word documents
It's not a secret anymore!