views:

122

answers:

4

How do you add a page number from java without using any third party library in a document and which can be treated as a new page in MS Word? Can Java create/manipulate an MS Document?

+1  A: 

Not without any third party libraries - unless you want to implement the file handling in your own code, of course... there's no built-in handling for Word documents.

You might be able to do something with Word 2007 documents which are basically zip files of XML files, but you'd still need to understand the format in a fair amount of detail. It would be a lot simpler to use a third party library rather than reinventing the wheel.

Jon Skeet
A: 

Not without a third part library.

POI is all I've ever used. Only made any use of the Excel portions, but they worked fairly well.

If you just need minor things you could implement the RTF file format yourself. Its not a small undertaking, but its actually practical. Sort of.

Kevin Montrose
A: 

This is probably well out of your scope but I'll mention it anyway in case it helps someone else.

Aspose.Words will do what you want, but it is commercial, and is quite expensive.

banjollity
A: 

if its a docx, you could use docx4j, which is a (my) third party library.

To do it without that: 1. unzip the docx 2. get the document.xml part 3. use xpath to identify the spot you want to insert your page break + number 4. insert 5. zip it up again and save ...

plutext