We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue while converting fields to static text

Hi
First, thank you for that, it’s working well but i’ve some problem at this line:

((Paragraph)nextParagraph).prependChild(paragraph.getLastChild());

Sometimes, “nextParagraph” seems to be null.

I replace this part by:

if(nextParagraph != null){
((Paragraph) nextParagraph).prependChild(paragraph.getLastChild());
}else{
break;
}

but that text is not appearing in document.

need help.

Hi,


Thanks for your inquiry. Please create a simple runnable Java application that helps us reproduce the same problem on our end and attach it here for testing. As soon as you get the source code ready, we’ll start our investigation into your issue and provide you more information.

Best regards,

Hi,


thanks for your reply. I am adding the sample code and the document which can’t convert to static text, please go through it need reply quickly.

thanks,
kapil

Hi Kapil,


Thanks for the details. The problem occurs because such fields do not have field values (FieldSeparator), could you please create and attach your expected Word document here for our reference. You can create your expected document using Microsoft Word. We need to visualize how you want your final document be generated like. We will then provide you code to achieve the same using Aspose.Words. Thanks for your cooperation.

Best regards,

Hi hafeez,

Thanks for your reply, actually that is the final document which i want to convert fields to static text.
but it returning null exception i want to handle that null pointer exception. if the fields doesn’t have value how can we set values to those fields.

thanks
kapil

Hi Kapil,


Thanks for your inquiry. In your document, each of these fields comprise of a FieldStart node, then a Run node and then a FieldEnd node. The Run node contains the field code e.g. “MACROBUTTON AcceptAllChangesInDoc “< enter >””, Microsoft Word displays only the text “< enter >”. The other two nodes i.e. FieldStart and FieldEnd are just field markers. I think, you can simply remove these markers from DOM hierarchy which will make them a static text. Please try executing the following code:
Document doc = new Document(getMyDir() + “test.rtf”);
DocumentBuilder builder = new DocumentBuilder(doc);

for (FieldStart start : (Iterable<FieldStart>) doc.getChildNodes(NodeType.FIELD_START, true)) {
if (start.getFieldType() == FieldType.FIELD_MACRO_BUTTON) {
((Run) start.getNextSibling()).getFont().setColor(new Color(0, 255, 0));
//((Run) start.getNextSibling()).setText(“Some static text”);
start.getField().getEnd().remove();
start.remove();
}
}

doc.save(getMyDir() + “out.rtf”);

I hope, this helps.

Best regards,

thanks for your solution, it’s helped me. but these behavior happens only for MACROBUTTON field or any other fields also have the same.

Hi Kapil,


Thanks for your inquiry. Yes, there are other fields too which might potentially cause the same issue, for example the “ListNum”, “AutoNum”, “AutoNumLegal”, “AutoNumOutline” fields etc. These fields don’t have values and Microsoft Word calculates and displays their values on the fly. You will be needing custom code for converting these fields to static text. I hope, this helps.

Best regards,