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

Free Support Forum - aspose.com

Bug: Changing PageSetup Margin affects Paragraph alignment

If you can the page setup margins on a document, the paragraph alignment is changed.

Below is the code that can reproduce the issue (Assert is from NUnit):

public void CreateDoc(string filename)
{
DocumentBuilder docBuilder = new DocumentBuilder();
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
docBuilder.Writeln(“Hello World”);
docBuilder.Document.Save(filename);
}

public void Test(string filename)
{
Document doc = new Document(filename);
doc.Sections[0].PageSetup.LeftMargin = 0.5;
doc.Sections[0].PageSetup.RightMargin = 0.5;
Assert.AreEqual(ParagraphAlignment.Center, doc.Sections[0].Body.Paragraphs[0].ParagraphFormat.Alignment);
}

public void Test()
{
CreateDoc(“test.doc”);
Test(“test.doc”);
}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce the problem on my side. Here is my code:

string fileName1 = @"Test116\out.doc";

string fileName2 = @"Test116\out1.doc";

DocumentBuilder docBuilder = new DocumentBuilder();

docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

docBuilder.Writeln("Hello World");

docBuilder.Document.Save(fileName1);

Document doc = new Document(fileName1);

doc.Sections[0].PageSetup.LeftMargin = 0.5;

doc.Sections[0].PageSetup.RightMargin = 0.5;

doc.Save(fileName2);

Assert.AreEqual(ParagraphAlignment.Center, doc.Sections[0].Body.Paragraphs[0].ParagraphFormat.Alignment);

Which version of Aspose.Words are you using for testing? I use the latest version (6.0.1).

Best regards.

I was using 6.0.0. I can try this with 6.0.1 and see if I have different results.

Adam

The test fails using 6.0.1 as well.

Here is a modified version of the test you ran, which outputs success / failure to the console.

using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Words;

namespace AsposeAlignmentTest
{
public class Program
{
static void Main(string[] args)
{
string fileName1 = @“out.doc”;
string fileName2 = @“out1.doc”;

DocumentBuilder docBuilder = new DocumentBuilder();
docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
docBuilder.Writeln(“Hello World”);
docBuilder.Document.Save(fileName1);

Document doc = new Document(fileName1);
doc.Sections[0].PageSetup.LeftMargin = 0.5;
doc.Sections[0].PageSetup.RightMargin = 0.5;
doc.Save(fileName2);

if (doc.Sections[0].Body.Paragraphs[0].ParagraphFormat.Alignment != ParagraphAlignment.Center)
{
Console.WriteLine(“Alignment Changed!!”);
}
else
{
Console.WriteLine(“Alignment Correct.”);
}
Console.WriteLine(“Press Any Key to Continue”);
Console.ReadKey();
}
}
}

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. All works fine on my side. Have tried open “out1.doc”. Is alignment of first paragraph changed?

Also please make sure that your application uses the latest version. Maybe it still uses 6.0.0.

Best regards.

My apologies, I simplified the test case too much.

The issue is the alignment of an inline image in the attached file. When the document is opened in Aspose and the Margins are changed, the image becomes left aligned.

public void AlignmentIssue()
{
string fileName = @“in.doc”;
string fileName2 = @“out1.doc”;

Document doc = new Document(fileName);

doc.Sections[0].PageSetup.LeftMargin = 72.0;
doc.Sections[0].PageSetup.RightMargin = 72.0;

doc.Save(fileName2);
}

Adam

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks you for additional information. Alignment of this image is not changed. The image in your document is Left aligned. You can see that if you make the image smaller. I changed your document so you will see the difference (I make image smaller and centered.)

Best regards.

I tested your document in both Word 2003 and Word 2007 and it is still centered. What version of Word were you using?

Adam

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. The imaged in my document is centered. I meant the image in your document is not centered.

Best regards.