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

Free Support Forum - aspose.com

How to get Border of Paragraph

I have a rtf document which contains a paragraph border. I want to replace the border with table programmatically using Aspose Api. But I am unable to get the borders using the examples given in your forum. I tried the following methods to get the borders but none of them are working.
indent preformatted text by 4 spaces

DocumentBuilder builder = new DocumentBuilder(doc);
Border topBorder = builder.ParagraphFormat.Borders[BorderType.Top];
StyleCollection sampleStyles = doc.Styles;
foreach (Aspose.Words.Style sampleStyle in sampleStyles)

            Font sampleStyleFont = sampleStyle.Font;
            if (sampleStyleFont != null)
                Border b = sampleStyleFont.Border;
                Shading s= sampleStyleFont.Shading;

In the above code, I am not able to get the border in the document. I am attaching the sample documentBorder.zip (8.6 KB).

Please help me in this regard.



Thanks for your inquiry. Please use ParagraphFormat.Borders property as shown below to get the collection of borders of the paragraph.

Following code example shows how to insert paragraph that has bottom border into table. Hope this helps you.

Document doc = new Document(MyDir + "Border.rtf");
Paragraph paragraph = doc.FirstSection.Body.Paragraphs[0];

//GET the border of paragraph

DocumentBuilder builder = new DocumentBuilder(doc);
//Insert the paragraph into table's cell.
if (paragraph.ParagraphFormat.Borders.Bottom != null)
    Table table = builder.StartTable();

    // Insert a cell
    Cell cell = builder.InsertCell();


doc.Save(MyDir + "18.7.docx");

Your example shows how to insert a border in a document. But I want to read all the borders present in the document. Please help me with that.


Thanks for your inquiry. The ParagraphFormat.Borders property returns collection of borders of the paragraph. To get the border of table’s cell, please use Cell.CellCellFormat.Borders. This method returns collection of borders of the cell.

I tried to get the borders present in the document by using “builder.ParagraphFormat.Borders”. But this always returns a collection with 6 length array of Border object for all the documents irrespective of a blank document or a document with borders in it.

All of these borders in the Borders collection having the same values as “IsVisible = false, LineStyle=None, LineWidth=0, Shadow=false”.

So, I cannot use this property to get the actual border present in the document.


Thanks for your inquiry. Please use Paragraph.ParagraphFormat.Borders property instead of “builder.ParagraphFormat.Borders”. We shared the code snippet in this thread. Please check the code snippet below.