Can it be done without any previously created document?
That mean instead doing this : Document doc = new Document("C:\\Temp\\Expected_Shape_Linking\\sample.docx");
I want to create shapes programmatically.
Sth like it does not work:
public static void test() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
final Shape shape = new Shape(builder.getDocument(), ShapeType.RECTANGLE);
builder.insertNode(shape);
shape.setTop(50);
shape.setLeft(50);
shape.setHeight(100);
shape.setWidth(100);
final Paragraph firstParagraph = new Paragraph(builder.getDocument());
shape.appendChild(firstParagraph);
builder.moveTo(firstParagraph);
builder.getFont().setColor(Color.BLUE);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.startBookmark("x");
FieldHyperlink link = (FieldHyperlink) builder.insertField(FieldType.FIELD_HYPERLINK, false);
link.setSubAddress("y");
link.setResult("XXXXX");
builder.endBookmark("x");
final Shape shape2 = new Shape(builder.getDocument(), ShapeType.RECTANGLE);
builder.insertNode(shape2);
shape2.setTop(200);
shape2.setLeft(200);
shape2.setHeight(100);
shape2.setWidth(100);
final Paragraph firstParagraph2 = new Paragraph(builder.getDocument());
shape2.appendChild(firstParagraph2);
builder.moveTo(firstParagraph2);
builder.getFont().setColor(Color.BLUE);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.startBookmark("y");
FieldHyperlink link2 = (FieldHyperlink) builder.insertField(FieldType.FIELD_HYPERLINK, false);
link2.setSubAddress("x");
link2.setResult("YYYY");
builder.endBookmark("y");
doc.updateFields();
saveDocument(builder, "awjava_");
}