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

Free Support Forum - aspose.com

Setting PageSetup destroys alignment

We are setting the PageSetup properties on a Section before creating a Body from it. When performing this action, it destroys the alignment of the created document. Skipping this step works, but we need the correct PageSetup for all the Sections we are creating so it is not an acceptable solution. Please see the attached sample project.
Though the sample project uses an outdated version, we have tried with the latest version and get the same results.


Thanks for your request. Actually I do not fully understand the purpose of your code. Why do you copy content from one section to another? It seems you just need to append one document to another. Am I right? If so, there is much simpler way than like you are using. Please see the following:
Could you please explain me the purpose of your code? Comments in your code would be great.
Best regards.

The code is an extremely simplified version of our code. We have a lot of additional logic that goes along with it, but I did not want to include all of our custom code so you could focus on the problem at hand. Basically we are taking pieces of the word document that could be a small as a single node to as large as multiple sections, and creating new documents from there. It is far more complicated than appending 1 document to another but I just wanted to use the smallest amount of code to demonstrate the problem.


Thank you for additional information. But I still think, that you implemented this in very hard way. I suppose the purpose of your code is producing section with the same PageSetup as the original section. In this case, you should not create section from scratch, as you do in your code. You can just clone section without cloning child nodes and import the cloned section into your destination document. Code will look like this:

// Open source document
Document src = new Document(@"Test001\in.doc");
// Create en empty destination document.
Document dst = new Document();
// Get section, which shoudl be copied into the destination document.
Section section = src.FirstSection;
// Clone section(without cloning child nodes).
Node clonedSection = section.Clone(false);
// Import section into the destination document.
Node importedSection = dst.ImportNode(clonedSection, true);
// Insert section into the destination document.
// Save output document.

As you may notice, the output document contains an empty section with the same PageSetup setting as the section in the original document.
Hope this could help you.
Best regards.

Thank you for your assistance. Changing:

documentComponentSection = new Aspose.Words.Section(documentComponentDocument);


documentComponentSection = (Aspose.Words.Section) nodeImporter.ImportNode(section.Clone(false), false);

has resolved the issue.