How to add tab inside a line

Hi,

I am attaching a sample document, in which contains titles along with paragraphs. While adding the title, first add the serial number part along with a tab and then add the title. paragraphs are indented the same with the title. I want to create such a document using Aspose word.

Attaching the sample document Sample.docx (13.5 KB)

Thank you

@Gptrnt You can achieve what you need using TabStop and LeftIndent of paragraph.
Here is a simple code example:

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

// Configure tab stop for the paragraphs.
builder.ParagraphFormat.TabStops.Add(100, TabAlignment.Left, TabLeader.None);

// Write some title.
builder.Font.Bold = true;
builder.Writeln("serial number #1\tThis is a title");

// Write simple paragraph.
builder.Font.Bold = false;
builder.ParagraphFormat.LeftIndent = 100;// the same as tabstop we have added.
builder.Writeln("This is cool item description that actually is dummy and nobody will read it. This is cool item description that actually is dummy and nobody will read it.");

// Reset left indent and write abother title.
builder.ParagraphFormat.LeftIndent = 0;
builder.Font.Bold = true;
builder.Writeln("serial number #2\tThis is a title");
builder.Font.Bold = false;
builder.ParagraphFormat.LeftIndent = 100;// the same as tabstop we have added.
builder.Writeln("This is cool item description that actually is dummy and nobody will read it. This is cool item description that actually is dummy and nobody will read it.");

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

Here is the output document produced by this code: out.docx (7.1 KB)

But since it is not very convenient to change formatting of document builder every time, you can define styles for this:

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

// Define style for title
Style title = doc.Styles.Add(StyleType.Paragraph, "MyTitle");
title.ParagraphFormat.TabStops.Add(100, TabAlignment.Left, TabLeader.None);
title.Font.Bold = true;

// Define style for text.
Style text = doc.Styles.Add(StyleType.Paragraph, "MyText");
text.ParagraphFormat.LeftIndent = 100;

// Add content
builder.ParagraphFormat.Style = title;
builder.Writeln("serial number #1\tThis is a title");
builder.ParagraphFormat.Style = text;
builder.Writeln("This is cool item description that actually is dummy and nobody will read it. This is cool item description that actually is dummy and nobody will read it.");

// adn once again
builder.ParagraphFormat.Style = title;
builder.Writeln("serial number #2\tThis is a title");
// Write simple paragraph.
builder.ParagraphFormat.Style = text;
builder.Writeln("This is cool item description that actually is dummy and nobody will read it. This is cool item description that actually is dummy and nobody will read it.");

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