MigraDoc table border issue with left indent

社会主义新天地 提交于 2019-12-11 01:21:52

问题


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:-

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

Here is what I'm getting


回答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.



来源:https://stackoverflow.com/questions/33371094/migradoc-table-border-issue-with-left-indent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!