Font formatting is lost after updating content control text using Java

@rabinintig

The input document (input.docx) does not allow to delete the text one by one character. So, the code generates the same output.

We suggest you please use the latest version of Aspose.Words for Java 20.3. If you want to use the input document that is generated by Aspose.Words, please generate it using the latest version of Aspose.Words.

@tahir.manzoor
sorry to say but same input file is working fine for BLOCK.
I need it will work for INLINE also.

@tahir.manzoor
For the same input, my previous code is working fine.
please help me to solve this problem with a new code.
I attached my previous code for your ref.
PFA
Test1 (2).zip (1.0 KB)

@rabinintig

Please use StructuredDocumentTag.IsShowingPlaceholderText property as shown below to get the desired output.

if(sdt.getSdtType() == SdtType.RICH_TEXT && sdt.getLevel() == MarkupLevel.INLINE)
{
    Run run = (Run) sdt.getFirstChild().deepClone(true);
    sdt.removeAllChildren();
    run.setText("AUTO999");
    sdt.appendChild(run);
    sdt.isShowingPlaceholderText(false);
}

@tahir.manzoor
It’s working fine.
thanks for help :slight_smile:

Hi @tahir.manzoor
I am facing another problem for handling the table.For Table contain control font is not change.
Can u please help me on this.

PFA
Test4.zip (49.5 KB)

@rabinintig

Please use the following code snippet to update the table’s cell text. Hope this helps you.

if (sdt.getSdtType() == SdtType.RICH_TEXT && sdt.getLevel() == MarkupLevel.CELL)
{

    sdt.isShowingPlaceholderText(false);
    fieldKey = sdt.getTag().replace("<", "").replace(">", "");

    Cell currentCell = (Cell) sdt.getFirstChild();
    double preferedWidth = currentCell.getCellFormat().getPreferredWidth().getValue();
    int type = currentCell.getCellFormat().getPreferredWidth().getType();

    //sdt.removeAllChildren();

    Paragraph paragraph = (Paragraph) currentCell.getFirstParagraph();
    Run run;
    if(paragraph.getRuns().getCount() > 0)
    {
        run = paragraph.getRuns().get(0);
    }
    else {
        run = new Run(doc);
        paragraph.appendChild(run);
    }
    run.setText("");

    String contentControlText = "table9999";
    sdt.isShowingPlaceholderText(false);
    System.out.println("inline" + sdt.getText());
    run.setText(contentControlText);
}

Hi @tahir.manzoor

  1. problem on handling contain control inside header.
    2.problem on handling contain control inside contain control.

PFA

test5.zip (35.7 KB)

@rabinintig

We have modified your code and attached it with this post. Please use the updated code to fix your issue. Hope this helps you.

code.zip (957 Bytes)

@tahir.manzoor
thanks.