• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphics and word documents

 
Michael Helgens
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right,

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,

-M
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Had you tried taking the image as a bit stream and writing at the start of word document ?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic