Taleeb
Taleeb

Reputation: 1919

MigraDoc table border issue with left indent

I'm trying to create a PDF document using MigraDoc, and am facing issues with table borders when the table contains a left indent.

I'm passing data to the following functions to render the table.

public void AddTable(int _iNumberOfColumns, double leftInd)
{
    table = section.AddTable();
    if (leftInd != 0d)
    {
        table.Format.LeftIndent = leftInd;
    }

    for (int i = 0; i < _iNumberOfColumns; i++)
    {
        Column col = table.AddColumn();
    }                
}

In the above method I'm passing a double value for the parameter leftInd. It is, I believe, the cause of the issue.

And the code to add cells is as follows. I'm passing bool variables to decide if the cells border needs to be visible or not... (To add a row I'm just calling row = table.AddRow();)

public void AddColumn(int _iCellNum, int iColspan, double dCellWidthInPt, System.Drawing.Color color, bool bTopBorder, bool bLeftBorder, bool bBottomBorder, bool bRightBorder)
{
    cell = row.Cells[_iCellNum];
            
    if (iColspan > 0)
    {
        cell.MergeRight = iColspan-1;
        for (int i = 0; i < iColspan; i++)
        {
            row.Cells[_iCellNum + i].Column.Width = new Unit(dCellWidthInPt, UnitType.Point);
        }
    }
    else
    {
        cell.Column.Width = new Unit(dCellWidthInPt, UnitType.Point);
    }
    //bRightBorder = bLeftBorder = bTopBorder = bBottomBorder = true;
    cell.Borders.Right.Visible = bRightBorder;
    cell.Borders.Left.Visible = bLeftBorder;
    cell.Borders.Top.Visible = bTopBorder;
    cell.Borders.Bottom.Visible = bBottomBorder;
    if (color!=null)
    {
        cell.Format.Shading.Color = new Color(color.A, color.R, color.G, color.B);
    }
            
}

I'm getting the following output:- enter image description here

If I remove the left indent the table renders properly (that is the left indent is not moving the table border to the left).

I cannot change the margin of the page as this table is part of document with a different margin. Similarly I cannot add a new section as that will add a new page.

Versions:

Migradoc: 1.32.3885.0

pdfSharp: 1.32.2608.0

Any suggestions on what I may be missing?

Edit

This is what I'm trying to achieve. See how the table is starting from more left as compared to the paragraph. To achieve this I'm trying to use table.Format.LeftIndent enter image description here

Here is what I'm getting enter image description here

Upvotes: 2

Views: 5373

Answers (1)

To indent the table, set table.Rows.LeftIndent. Negative values also work.

As written in a comment, table.Format.LeftIndent sets the default indentation for all paragraphs in the table cells, so it moves the text, but not the borders.

Upvotes: 6

Related Questions