2

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

4
  • Your code is neither minimal nor complete. I don't understand why you set LeftIndent if it causes problems. I don't understand what the problem is. What are you trying to achieve? Maybe table.Format.LeftIndent is not the way to do it. Commented Oct 27, 2015 at 16:53
  • Though my code is not complete - this is the only part which is relavant. The problem I am facing (as shown in the attached image) is that the column data (see first cell/column) is responding to the table's leftIndent. But the cell/column border is starting as per page margin.. I am setting left indent so that the table should start from left (as compared to page margin). So if the page left margin is 10", table's is 8" Commented Oct 27, 2015 at 16:58
  • The documentation says that table.Format.LeftIndent is the indentation for all paragraphs in the table cells. This is not the way to indent the table. Much like CSS you can set this at the Table, the Cell, or individual Paragraphs. You show two methods, but you do not show with which parameters you call the methods. So relevant information is missing IMHO. If you want to indent the table and not the text in the table cells, then put that into the questions (maybe with a question mark at the end). Commented Oct 27, 2015 at 17:55
  • @ThomasH. I've edited the question and added some more images of what I'm trying to do and what I'm getting... Hopefully this would help in clearing the question a bit more. Commented Oct 27, 2015 at 18:14

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. That does make sense! Let me test and will then accept the answer :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.