How do i add a Horizontal Line through Aspose words to my word document

Hi

I require to create a word document which needs to have various paragraphs separated by a Horizontal line. I am unable to find a way. please provide assistance.

my another query deals with how to provide formatting for setting the background color of a line in a paragraph. i founded there is a way to set background for a paragraph using (builder.ParagraphFormat.Shading.BackgroundPatternColor), but i require to set for a particular line in a paragraph.

Regards

Vivek bahl

Here is a sample code that writes several paragraphs with horizontal line between them:

// Open new document.
string filenameOut = Application.StartupPath + @"\testSeparatorLine Out.doc";
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set builder to insert horizontal line between paragraphs.
Border border = builder.ParagraphFormat.Borders[BorderType.Horizontal];
border.LineStyle = LineStyle.Single;
border.LineWidth = 1;
border.Color = Color.Brown;
border.Shadow = true;
// Write two paragraphs.
builder.Writeln("The quick brown fox jumps over the lazy dog.");
builder.Writeln("The quick brown fox jumps over the lazy dog.");
// Save document to file.
doc.Save(filenameOut);
// Open saved document in MS Word.
System.Diagnostics.Process.Start(filenameOut);

Concerning background color of a line in a paragraph please explain what is meant here. Border lines in MS Word do not have background color as far as I know. Please make a sample document in MS Word illustrating your point.

Best regards,

Thanks for answering Ist query, my second query deals with how to provide formatting for setting the background color of a line of text in a paragraph.

i founded there is a way to set background for a paragraph using (builder.ParagraphFormat.Shading.BackgroundPatternColor), but i require to set for a particular line of text in a paragraph.

This is a tricky question. MS Word (as well as Aspose.Words) does not operate with lines of text. Text is organized into runs, which are in turn make paragraphs. Run is an arbitrary amount of text inside paragraph which have similar character formatting. You can mark line of text in MS Word and set background color for it. MS Word will then reorganize run structure inside paragraph to be able to apply this formatting to selected text. Aspose.Words API does not permit the same action to be applied easily. You can apply background color to any run inside a given paragraph, but reorganization (splitting and merging) of runs inside paragraph to set background color to a line of text may become a challenging task. One more complication is that Aspose.Words operates with information stored in document binary and does not make page layout as MS Word does, when it loads the document. So you won’t be able to define easily how paragraph is laid out into lines on a page.

You can easily see for yourself in MS Word. If you mark the line of text with a background color and then change the text or page size you will see that the color won’t stay on one line but will only continue to mark the same text no matter how many lines it will take due to page resize or text change.

Hope that answers your question,

Hello,

I think he meant adding horizonal line. I.e. in the “AutoShape” toolbar, drag and drop a line.

it put it iside the “drawing canvas”.

I have the same question too. How do I create such line in Aspose Word.

Thanks

Yair

miklovan:

This is a tricky question. MS Word (as well as Aspose.Words) does not operate with lines of text. Text is organized into runs, which are in turn make paragraphs. Run is an arbitrary amount of text inside paragraph which have similar character formatting. You can mark line of text in MS Word and set background color for it. MS Word will then reorganize run structure inside paragraph to be able to apply this formatting to selected text. Aspose.Words API does not permit the same action to be applied easily. You can apply background color to any run inside a given paragraph, but reorganization (splitting and merging) of runs inside paragraph to set background color to a line of text may become a challenging task. One more complication is that Aspose.Words operates with information stored in document binary and does not make page layout as MS Word does, when it loads the document. So you won’t be able to define easily how paragraph is laid out into lines on a page.

You can easily see for yourself in MS Word. If you mark the line of text with a background color and then change the text or page size you will see that the color won’t stay on one line but will only continue to mark the same text no matter how many lines it will take due to page resize or text change.

Hope that answers your question,

Answered in this thread.