Hi
Thank you for your interest in Aspose.Words for java.
- TOC updating is not yet supported by .NET and Java versions of Java. We plan to support this feature in one of the future releases of .NET version. Afterward, this feature will be ported to Java version. I cannot promise anything at this stage. Hopefully, TOC updating will be supported Aspose.Words for Java in the end of this year.
- Same for TOF
- You can insert watermark into the document using Aspose.Words. just insert image into the header of the document (as MS Word does). See the following code for instance:
///
/// Inserts watermark into the document
///
/// Input document
/// Text of waermark
private static void InsertWatermarkText(Document doc, String watermarkText) throws Exception
{
// Create whatermark shape
// This will be WordArt shape. You are free to use any type of shape as watermark
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
// This will be text of watermark
watermark.getTextPath().setText(watermarkText);
watermark.getTextPath().setFontFamily("Times New Roman");
watermark.setWidth(600);
watermark.setHeight(100);
// Text dirrection will be from bottom-left corner to top-right
watermark.setRotation(-45);
// Uncomment the following line if you need solid black text
watermark.getFill().setColor(Color.GRAY);
watermark.setStrokeColor(Color.GRAY);
// Set position of watermark
// Watermark should be placed on the center of page
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
// Create new paragraph and append watermark to this paragraph
Paragraph watermarkPar = new Paragraph(doc);
watermarkPar.appendChild(watermark);
int[] hfTypes = { HeaderFooterType.HEADER_PRIMARY, HeaderFooterType.HEADER_FIRST, HeaderFooterType.HEADER_EVEN };
// Now we should insert watermark into the header of each section of document
for (Section sect : doc.getSections())
{
for (int hftype : hfTypes)
{
if (sect.getHeadersFooters().getByHeaderFooterType(hftype) == null)
{
// If there is no header of the specified type in the current section we should create new header
if (hftype == HeaderFooterType.HEADER_PRIMARY ||
hftype == HeaderFooterType.HEADER_FIRST && sect.getPageSetup().getDifferentFirstPageHeaderFooter() ||
hftype == HeaderFooterType.HEADER_EVEN && sect.getPageSetup().getOddAndEvenPagesHeaderFooter())
{
HeaderFooter hf = new HeaderFooter(doc, hftype);
// Insert clone of watermarkPar into the header
hf.appendChild(watermarkPar.deepClone(true));
sect.getHeadersFooters().add(hf);
}
}
else
{
// If the header of specified type exists then just insert watermark
sect.getHeadersFooters().getByHeaderFooterType(hftype).appendChild(watermarkPar.deepClone(true));
}
}
}
}
- Captions in MS Word are represented as “Lable” + “SEQ field”. You can use DocumentBuilder for inserting captions. For example see the following code:
Document doc = new Document("C:\\Temp\\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get collection of shapes inthe document
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
// Loop through all shpes
for (int shapeIdx = 0; shapeIdx < shapes.getCount(); shapeIdx++)
{
Shape shape = (Shape)shapes.get(shapeIdx);
if (shape.getShapeType() == ShapeType.IMAGE)
{
// Move DocumentBuilder cursor to shape
// Cursor will be placed after shape
if (shape.getNextSibling() != null)
builder.moveTo(shape.getNextSibling());
else
builder.moveTo(shape.getParentParagraph());
// Insert paragraph break
builder.writeln();
// Insert lable
builder.write("Picture");
// Insert SEQ field
builder.insertField("SEQ Picture \\* ARABIC", "");
}
}
// Save result document
doc.save("C:\\Temp\\out.doc");
However, note that Aspose.Words does not evaluate SEQ fields. So you should update fields inside the document manually (ctrl+A and F9). In addition, you can use macro to update fields. See the following link to learn more.
https://support.microsoft.com/en-us/topic/the-filename-field-does-not-automatically-update-when-you-open-a-document-in-word-de2bfb95-d990-1ced-a618-5ac0a2ec1be4
Hope this helps.
Best regards.