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

Free Support Forum - aspose.com

Help with Word Alignment Tabs

Hi

I am using Visual Studio 2013, with Aspose Words 15.7. Also MS Word 2010.

I am creating a Word document programmatically, and would like to use Word’s Alignment Tab feature in the headers and footers. However, I can’t seem to figure out how to do it.

This post seems to imply that there is a class called AbsolutePositionTab that could do the trick, but I am unable to figure out how to use it (if, indeed, it is the correct class to use). There is no public constructor, and no method that I can see to insert or create it in either the Document or the DocumentBuilder classes.

I’ve searched the forums, and come up empty. Does anyone have any ideas?

I’m currently inserting a table into the header/footer, with cells aligned to left/centre/right as needed, but the drawback to that is, I get a extra line feed in the header or footer directly after the table - which throws out the vertical alignment for footers.

Thanks
Chris Fairall.

Hi Chris,

You can use any of the following solution which suits your requirement.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

// X * 72 = X inches

builder.ParagraphFormat.TabStops.Add(6*72, TabAlignment.Right, TabLeader.Dashes);

builder.Writeln("Left Header" + ControlChar.Tab + "Right Header");<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

doc.Save(“Test.docx”);

or

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

// X * 72 = X inches

builder.Document.DefaultTabStop
= 2.5*72;

builder.Writeln(“Left Header” + ControlChar.TabChar

  • “Left Header” + ControlChar.TabChar + “Right
    Header”
    );<o:p></o:p>

doc.Save(“Test.docx”);

Best Regards,

Hi Muhammad


Thanks for your reply. While your solution is not ideal, it might have to do for the time being if Word alignment tabs are not currently supported in document creation.

Is there a way to determine the width of the page? If I set the paper size to A4, or B5, or Letter, or whatever, is there a field that will tell me the actual width of the page in points?

Thanks
Chris.

Hi Chris,

You can use builder.CurrentSection.PageSetup.PageWidth; to get the width in points.

Best Regards,

Thanks very much for that Muhammad. That worked perfectly.


Chris