Need to output tab aligned text with custom tab stop settings

I am currently creating custom tab stops and placing text at each tab stop. I am trying to have the text wrap at the tab (tab aligned text) when it runs over the width of the page. I have set the tabStop.Alignment to Left and it doesn’t work. code sample below.

private void SetTabStops(DocumentBuilder myBuilder)
{
    Paragraph paragraph = (Paragraph)myBuilder.Document.GetChild(NodeType.Paragraph, 0, true);
    paragraph.ParagraphFormat.ClearFormatting();
    paragraph.ParagraphFormat.StyleIdentifier = StyleIdentifier.BodyText;
    paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Left;
    paragraph.ParagraphFormat.LineSpacingRule = LineSpacingRule.AtLeast;
    paragraph.ParagraphFormat.LineSpacing = 1;
    paragraph.ParagraphFormat.TabStops.Clear();
    paragraph.ParagraphFormat.WordWrap = true;


    TabStop tabStop = new TabStop(ConvertUtil.InchToPoint(.25), TabAlignment.Left, TabLeader.None);
    paragraph.ParagraphFormat.TabStops.Add(tabStop);

    tabStop = new TabStop(ConvertUtil.InchToPoint(.5), TabAlignment.Left, TabLeader.None);
    paragraph.ParagraphFormat.TabStops.Add(tabStop);

    tabStop = new TabStop(ConvertUtil.InchToPoint(1.0), TabAlignment.Left, TabLeader.None);
    paragraph.ParagraphFormat.TabStops.Add(tabStop);

    tabStop = new TabStop(ConvertUtil.InchToPoint(1.5), TabAlignment.Left, TabLeader.None);
    paragraph.ParagraphFormat.TabStops.Add(tabStop);
}

Code that writes the data:

myBuilder.Write(string.Format("\t\t{0}\t", myControlPartsList.Rows[p]["PartLabel"].ToString()));
myBuilder.Writeln(String.Format("{0}", myControlPartsList.Rows[p]["FullStatement"].ToString()));

@volpet2014 Could you please create an expected output in MS Word attach it here? We will check the document and provide you a solution or more information.

See attached images. SampleOutputGood.JPG (61.5 KB)
SampleOutputBad.JPG (58.3 KB)
AsposeWordSampleOutput.docx (12.7 KB)

@volpet2014 Thank you for additional information. You should use hanging indentation of paragraph:


You can achieve this by setting negative value of ParagraphFormat.FirstLineIndent and ParagraphFormat.LeftIndent to the same positive value.
For example see the following simple code:

Document doc = new Document();
DocumentBuilder builer = new DocumentBuilder(doc);

double position = 100;

builer.ParagraphFormat.TabStops.Clear();
builer.ParagraphFormat.TabStops.Add(position, TabAlignment.Left, TabLeader.None);

builer.ParagraphFormat.LeftIndent = position;
builer.ParagraphFormat.FirstLineIndent = -position;

builer.Write("\tThis it some text that should be wrapped and the second line of text should be inlined with tab position.");

doc.Save(@"C:\Temp\out.docx");

Also, it looks like you are building some kind of list. I think it will be much easier to use list:

Document doc = new Document();
DocumentBuilder builer = new DocumentBuilder(doc);

// Create and configure list.
List lst = doc.Lists.Add(ListTemplate.OutlineNumbers);
lst.ListLevels[0].NumberStyle = NumberStyle.LowercaseLetter;
lst.ListLevels[0].NumberFormat = "\x0000.";

lst.ListLevels[1].NumberStyle = NumberStyle.Arabic;
lst.ListLevels[1].NumberFormat = "\x0001.";
            
lst.ListLevels[2].NumberStyle = NumberStyle.LowercaseLetter;
lst.ListLevels[2].NumberFormat = "(\x0002)";

builer.ListFormat.List = lst;

builer.Writeln("Develop, document, and disseminate to [organization-defined personnel or roles]:");
builer.ListFormat.ListIndent();
builer.Writeln("[organization-level; mission/business process-level; system-level] access control policy that:");
builer.ListFormat.ListIndent();
builer.Writeln("Addresses purpose, scope, roles, responsibilities, management commitment, coordination among organizational entities, and compliance; and");
builer.Writeln("Is consistent with applicable laws, executive orders, directives, regulations, policies, standards, and guidelines; and");
builer.ListFormat.ListOutdent();
builer.Writeln("Procedures to facilitate the implementation of the access control policy and the associated access controls;");
builer.ListFormat.ListOutdent();
builer.Writeln("Designate an [organization-defined official] to manage the development, documentation, and dissemination of the access control policy and procedures; and");
builer.Writeln("Review and update the current access control:");
builer.ListFormat.ListIndent();
builer.Writeln("Policy [organization-defined frequency] and following [organization-defined events]; and");
builer.Writeln("Procedures [organization-defined frequency] and following [organization-defined events].");

builer.ListFormat.RemoveNumbers();

doc.Save(@"C:\Temp\out.docx");