How to get Border of Paragraph

Hi,
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,

@jayadn,

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
Console.WriteLine(paragraph.ParagraphFormat.Borders.Bottom.LineStyle);
Console.WriteLine(paragraph.ParagraphFormat.Borders.Bottom.LineWidth);

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

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

    builder.EndTable();
    cell.RemoveAllChildren();
    cell.Paragraphs.Add(paragraph.Clone(true));
    cell.FirstParagraph.ParagraphFormat.Borders.ClearFormatting();

    paragraph.Remove();
}
                 
doc.Save(MyDir + "18.7.docx");

Hi,
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.

@jayadn,

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.

@jayadn,

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.