We have created a word document with multiple content control using aspose library, then we have modified indentation of document with -ve value using microsoft word. For example for any content control or paragraph indent value is -1.37 or some -ve value.
Now we are trying to replace an replace content in any content control in this document such that indentation of existing content control in document should be preserved.
While processing document, we move documentBuilder to the respective paragraph and we are setting leftIndent property from existing paragraph to documentBuilder and inserting the new content there.
documentBuilder.getParagraphFormat().setLeftIndent(paragraph.getParagraphFormat().getLeftIndent());
Now on each update, paragraph is moving right with some points, even if identation get’s positive in procedure, it continues to move paragraph to right.
While it’s working fine in case we set +ve indentation in original document, indentation is getting preserved.
How we can preserve in case of -ve identation ?
@govindsgs Could you please attach your document and the expected result here for testing? We will check the issue and provide you more information.
ReplaceContent.docx (12.2 KB)
FormattedDoc.docx (30.5 KB)
FormattedDoc is document with -ve indent and I am trying to replace an content control ABCDEFGH with replaceContent and want to preserve -ve indentation in updated document.
@govindsgs Thank you for additional information. Actually negative indent is set in paragraphs, which are inside content control not in SDT itself. When you remove the paragraphs and insert paragraphs from your another document, formatting of paragraphs from the source document is preserved. So Aspose.Words behavior here is correct.
If you need to preserve negative indent of paragraphs inside SDT after inserting content, you should loop through inserted paragraphs and set negative indent.
we are setting in same manner as you are saying, there is no issue if there is no numbering associated with content in original document, Issue is with line number, if document is having line items whose identation also align with paragraph content, then issue is coming, using the same method to preserve, it’s not preseving all identation less than 1.27 cm or 36 points and it’s giving unexpected identation results in updated document. As verfied, while saving documentBuilder is having correct value of identation. I doubt on save method.
@govindsgs Could you please attach your current output document and expected output documents here along with code you are using to update content of content control in your document? We will check the issue and provide you more information.
ReplaceData.docx (13.0 KB)
result.docx (23.6 KB)
indentedOriginal.docx (29.3 KB)
we want to preseve identation as there in indentOriginal document.
@govindsgs Could you please provide code you are using to update Content control content?
I have tested with the following simple code:
Document dst = new Document("C:\\Temp\\result.docx");
Document src = new Document("C:\\Temp\\ReplaceData.docx");
// Find SDT where is is required to update content.
StructuredDocumentTag sdt;
Iterable<StructuredDocumentTag> sdts = dst.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true);
for (StructuredDocumentTag s : sdts)
{
if (s.getTitle().equals("ABCDEFGH"))
{
sdt = s;
break;
}
}
// Remove old content.
sdt.removeAllChildren();
// Copy content from the soruce document into SDT.
for (Node child : (Iterable<Node>)src.getFirstSection().getBody().getChildNodes())
{
Node dstNode = dst.importNode(child, true, ImportFormatMode.KEEP_SOURCE_FORMATTING);
sdt.appendChild(dstNode);
}
dst.save("C:\\Temp\\out.docx");
In the result document formatting of the source document is preserved.