UpdateFields made field text bold unexpectedly using Aspose.Words

Hi,

When running UpdateFields() on a document, I noticed the field text in the footer was refreshed in bold even if the field was not in bold and the field style is set to be preserved.

Code:
var document = new Document(“test.docx”);
document.UpdateFields();
document.Save(“testout.docx”);

I’ve attached the test and output file for your reference. You can see the field in the footer of original document is not in bold but in the output document it is bold.

Could you please take a look into this?

Thanks,

test.zip (23.4 KB)

@ServerSide527,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-15857. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi, Tahir. I have the same issue when I updateFields() in aspose I see the text to be in bold after save.
Any solution work around for it?

@kiran5388 Unfortunately, the issue is not resolved yet. Could you please attach your input, output document and code that will allow us to reproduce the problem? We will check whether you have encountered the same problem.

Is it solved in the latest version now?

@Crane The issue reported in this thread is not resolved yet. It has been postponed and is not yet scheduled for development. Please accept our apologies for your inconvenience.

Is there a temporary solution? Change the text style of the fields.

@Crane Could you please attach your input, output document and code that will allow us to reproduce the problem? We will check whether you have encountered the same problem.

  @Test
  public void generateHeader() throws Exception {
    Document document = new Document();
    com.aspose.words.List list = addList(document);
    DocumentBuilder documentBuilder = new DocumentBuilder(document);
    documentBuilder.write("绪论");
    documentBuilder.getCurrentParagraph().getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
    documentBuilder.getCurrentParagraph().getListFormat().setList(list);
    documentBuilder.getCurrentParagraph().getListFormat().setListLevelNumber(0);
    documentBuilder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
    documentBuilder.write("引言");
    documentBuilder.getCurrentParagraph().getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
    documentBuilder.getCurrentParagraph().getListFormat().setList(list);
    documentBuilder.getCurrentParagraph().getListFormat().setListLevelNumber(0);
    documentBuilder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
    for (Section section : document.getSections()) {
      HeaderFooter headerFooter = new HeaderFooter(document, HeaderFooterType.HEADER_FIRST);
      section.getHeadersFooters().add(headerFooter);
      Paragraph paragraph = new Paragraph(document);
      paragraph.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
      paragraph.appendField("STYLEREF \"标题 1\" \\n");
      paragraph.appendField("STYLEREF \"标题 1\"  \\* MERGEFORMAT");
      for (Object childNode : paragraph.getChildNodes(NodeType.RUN, true)) {
        if (childNode instanceof Run run) {
          run.getFont().setBold(false);
          run.getFont().setColor(Color.RED);
        }
      }
      headerFooter.getParagraphs().add(paragraph);
      PageSetup pageSetup = section.getPageSetup();
      pageSetup.setDifferentFirstPageHeaderFooter(true);
      pageSetup.setBorderSurroundsHeader(true);
      pageSetup.setOddAndEvenPagesHeaderFooter(true);
    }
    document.save("header.docx");
  }

@Crane Thank you for additional information. Unfortunately, I cannot reproduce the problem on my side. I have changed text and style names to English (default) for testing:

Document document = new Document();
com.aspose.words.List list = document.getLists().add(ListTemplate.NUMBER_DEFAULT);
DocumentBuilder documentBuilder = new DocumentBuilder(document);
documentBuilder.write("This is some text");
documentBuilder.getCurrentParagraph().getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
documentBuilder.getCurrentParagraph().getListFormat().setList(list);
documentBuilder.getCurrentParagraph().getListFormat().setListLevelNumber(0);
documentBuilder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
documentBuilder.write("Another text");
documentBuilder.getCurrentParagraph().getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
documentBuilder.getCurrentParagraph().getListFormat().setList(list);
documentBuilder.getCurrentParagraph().getListFormat().setListLevelNumber(0);
documentBuilder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
for (Section section : document.getSections()) {
    HeaderFooter headerFooter = new HeaderFooter(document, HeaderFooterType.HEADER_FIRST);
    section.getHeadersFooters().add(headerFooter);
    Paragraph paragraph = new Paragraph(document);
    paragraph.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
    paragraph.appendField("STYLEREF \"Heading 1\" \\n");
    paragraph.appendField("STYLEREF \"Heading 1\"  \\* MERGEFORMAT");
    for (Object childNode : paragraph.getChildNodes(NodeType.RUN, true)) {
        if (childNode instanceof Run) {
            Run run = (Run)childNode;
            run.getFont().setBold(false);
            run.getFont().setColor(Color.RED);
        }
    }
    headerFooter.getParagraphs().add(paragraph);
    PageSetup pageSetup = section.getPageSetup();
    pageSetup.setDifferentFirstPageHeaderFooter(true);
    pageSetup.setBorderSurroundsHeader(true);
    pageSetup.setOddAndEvenPagesHeaderFooter(true);
}
document.updateFields();
document.save("C:\\Temp\\out.docx");

out.docx (9.8 KB)