Hi Team,
I want to merge 2 consecutive Structured document tags into 1 tag while maintaining the spacing between the paragraphs
Currently am using the code below for merging
public static void main(String[] args) throws Exception {
Document document = new Document("..\\158464.docx");
StructuredDocumentTag prevStd = null;
for (Object st : document.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
StructuredDocumentTag std = (StructuredDocumentTag) st;
if (prevStd == null) {
prevStd = std;
continue;
}
if ((std.getSdtType() == SdtType.RICH_TEXT)) {
Boolean consecutiveNode = false;
//Check for nodes between stds , this is to check of we can merge stds or not.
consecutiveNode = true;
List intermediateNodes = null;
try {
intermediateNodes = new BookMarkNodeExtractorService().extractContent(prevStd, std, false);
} catch (Exception ex) {
//LOGGER.warn("not able to extract bookmark node in the StructuredDocumentTag due to : ", ex);
consecutiveNode = false;
}
if (!ListUtil.isEmpty(intermediateNodes)) {
for (Object node : intermediateNodes) {
if (!StringUtil.isEmpty(((Node) node).getText().trim())) {
consecutiveNode = false;
break;
}
}
}
if (Boolean.TRUE.equals(consecutiveNode)) {
prevStd.appendChild(std);
std.removeSelfOnly();
}
}
}
document.save("..\\158464_Test.docx");
System.out.println("Doc generated");
}
but the new merged SDT is not maintaining the spaces and lines between consecutive SDTs
Attaching the input and output documents
please suggest the best way to retain spacing and lines between SDTs
input document -
158464.docx (33.9 KB)
output document
158464_Test.docx (27.4 KB)