Free Support Forum - aspose.com

Table border DashArray ignored

I’m trying to create a table with a dashed border, but it seems not to work.

Simple example:

    Document doc = new Document();

    Page page = doc.Pages.Add();

    GraphInfo borderStyle = new GraphInfo()
    {
        Color = Color.Pink,
        DashArray = new int[] { 5, 5 },
        LineWidth = 1.0f,
    };

    var container = new Table
    {
        Border = new BorderInfo(BorderSide.All, borderStyle)
    };

    Cell cell = new Cell()
    {
        Alignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center
    };

    cell.Paragraphs.Add(new TextFragment("hello"));

    container.Rows.Add().Cells.Add(cell);

    page.Paragraphs.Add(container);

    doc.Save(@"C:\temp\test.pdf");

@JamieTemple

Thanks for contacting support.

We tried to add the dashed border around table by modifying your code as following and were unable to do so. However, we noticed that if we skip Top side of table and specify remaining three sides for GraphInfo, the dashed border renders in the output correctly.

GraphInfo borderStyle = new GraphInfo()
{
 Color = Color.Pink,
 DashArray = new int[] { 5, 5 }, // this property is for dashed border
 LineWidth = 2f,
 DashPhase = 1 // this property is for dashed border
};
borderInfo.Top = borderInfo.Bottom = borderInfo.Left = borderInfo.Right = borderStyle;
// Comment above and uncomment below line and dashed border will appear except top of the table
//borderInfo.Bottom = borderInfo.Left = borderInfo.Right = borderStyle;
var container = new Table
{
  Border = borderInfo
};

We have logged an investigation ticket as PDFNET-45704 in our issue tracking system for this behavior of the API. We will investigate this in details and keep you posted with the results of investigation. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hello,

Thanks for the quick response.

Unfortunately, three sides won’t cut-it for me, as I am trying to draw a nice dashed border around my box.

I’ll keep an eye out for updates.

In the meantime, I guess I’ll just have to draw the dashed rectangle onto a canvas … mildly annoying, as it won’t be responsive to the height of the table contents like a border would be, but I can work with this for now.

As an aside, I couldn’t find anything describing what DashPhase does - it seems like an undocumented magic number - any chance of enlightening me?

Thanks again,

Jamie.

@JamieTemple

Thanks for writing back.

We will definitely let you know once logged ticket is resolved.

The DashPhase Property is used to set phase i.e. distance from start of pattern. For example, if we have pattern like -----+++++, it will be drawn as -----+++++-----+++++ for DashPhase = 0 and ---+++++-----+++++ if DashPhase = 2. In case of any further assistance, please feel free to let us know.