Hello,
I would like to create a link between two shapes. In ms Word I just
create eg: rectangle and circle
right mouse button on shape --> Add text
I enter some text and I wrap it as a bookmark.
Finally, I can connect shapes based on their text using bookmark linking. How to achieve the same result using aspose?
I tried
final Shape rectangleShape = new Shape(builder.getDocument(), ShapeType.RECTANGLE);
final Paragraph firstParagraph = new Paragraph(builder.getDocument());
shape.appendChild(firstParagraph);
builder.moveTo(paragraph); // I cant move cusror there and call builder.insertHyperlink(...)
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_");
}
That was a working example and thank you. But I suggest correct this behaviour when someone can’t move the cursor directly from one paragraph placed into some shape into another without going back to the paragraph placed on the page. (level 0? )
Unfortunately, your question isn’t clear enough therefore we request you to please elaborate your inquiry further by providing complete details of your problem along with sample Word documents and screenshots. This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.