While trying to insert Image, it is retaining the properties of the next Heading

Hello, I am getting the following output (attaching screenshot Output received.png (66.9 KB)
for your reference)

  • The first image is taking the Heading Properties of the list heading.
    I want it to be inserted and then, get the next heading followed by the next image.
    Required output.png (47.8 KB)

Code:

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
builder.getListFormat().setList(mainList);
builder.getListFormat().listIndent();
builder.getListFormat().getListLevel().setNumberStyle(NumberStyle.ARABIC);
builder.getListFormat().getListLevel().setNumberFormat("\u0000.\u0001");
fontStyles.SetSubHeading(font); // custom method
builder.writeln("Scenario of Application Flows Diagram");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.BODY_TEXT);
builder.getListFormat().setList(null);
fontStyles.SetTextFont(font); // Custom method

// The four lines used below to set properties of inserted image has been included in a method 'insertDiagrams' in a separate class and I am calling it as a reference 

Shape shape = builder.insertImage(ImageIO.read(url)); // url is a URL object
shape.setWrapType(WrapType.TOP_BOTTOM);
shape.setWidth(300);
shape.setHeight(300);

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
builder.getListFormat().setList(mainList);
builder.getListFormat().listIndent();
builder.getListFormat().getListLevel().setNumberStyle(NumberStyle.ARABIC);
builder.getListFormat().getListLevel().setNumberFormat("\u0000.\u0001");
fontStyles.SetSubHeading(font);
builder.writeln("Application Technical Architecture Diagram");

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.BODY_TEXT);
builder.getListFormat().setList(null);
fontStyles.SetTextFont(font);

// The four lines used below to set properties of inserted image has been included in a method 'insertDiagrams' in a separate class and I am calling it as a reference 

Shape shape = builder.insertImage(ImageIO.read(url)); // url is a URL object
shape.setWrapType(WrapType.TOP_BOTTOM);
shape.setWidth(300);
shape.setHeight(300);

@simikadampatta The following code in your code example changes style of the same paragraph:

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.BODY_TEXT);
builder.getListFormat().setList(null);
fontStyles.SetTextFont(font); // Custom method

Shape shape = builder.insertImage(ImageIO.read(url)); // url is a URL object
shape.setWrapType(WrapType.TOP_BOTTOM);
shape.setWidth(300);
shape.setHeight(300);

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);

First you assign BODY_TEXT style to the paragraph and then after inserting image you assign HEADING_2 style to the same paragraph. If you need the image to be place in the separate paragraph, you should put builder.writeln(); after inserting the image.

1 Like

Thank you for your help!
Adding builder.writeln() worked.