It seems that after copying headers from the second section to the first section, the paragraph alignment has changed unexpectedly. This can happen due to various reasons related to how headers and footers are managed in the document.
To address this issue, you can ensure that the paragraph formatting in the headers of the first section is explicitly set after copying the headers. Here’s a general approach you can take:
Check Paragraph Alignment: After copying the headers, explicitly set the paragraph alignment for the headers in the first section to match your desired alignment (e.g., right alignment).
Use DocumentBuilder: If you are using DocumentBuilder, you can set the alignment like this:
Document doc = new Document("C:\\Users\\z_jia\\Desktop\\a\\out.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Move to the header of the first section
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT); // Set to right alignment
Reapply Formatting: After copying the headers, you may want to loop through the headers in the first section and reapply the desired formatting to ensure consistency.
Here’s a code snippet that demonstrates how to copy headers and set the alignment:
Section section1 = sections.get(0);
Section section2 = sections.get(1);
HeaderFooterCollection headersFooters2 = section2.getHeadersFooters();
for (int z = 0; z < headersFooters2.getCount(); z++) {
HeaderFooter headerFooter2 = headersFooters2.get(z);
Node clonedHeaderFooter = word.importNode(headerFooter2, true);
section1.getHeadersFooters().add(clonedHeaderFooter);
}
// Set alignment for the copied headers
for (HeaderFooter headerFooter : section1.getHeadersFooters()) {
for (Paragraph paragraph : headerFooter.getChildNodes(NodeType.PARAGRAPH, true)) {
paragraph.getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT); // Set to right alignment
}
}
By ensuring that the paragraph alignment is explicitly set after copying the headers, you should be able to maintain the desired formatting in your document. If the issue persists, consider checking other formatting settings that might be affecting the alignment.
@GusGus
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-27722
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@GusGus We have completed analyzing the issue. And we are going to close this issue as Not a Bug.
The output in MS Word and Aspose.Words is the same. The reason of changed alignment is that problematic paragraph has built-in style Footer that has different alignment in source and destination documents.
If you want to preserve source document formatting and layout, then please try our Merger feature:
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.