C#MigraDoc边距不正确?

时间:2016-06-20 11:38:12

标签: c# pdf pdfsharp margins migradoc

左边距和上边距不是7毫米。为什么呢?

Document document = new Document();

Section sec = document.AddSection();
sec.PageSetup.PageWidth = Unit.FromMillimeter(210);
sec.PageSetup.PageHeight = Unit.FromMillimeter(297);
sec.PageSetup.LeftMargin = Unit.FromMillimeter(7);
sec.PageSetup.TopMargin = Unit.FromMillimeter(7);
sec.PageSetup.RightMargin = Unit.FromMillimeter(7);
sec.PageSetup.BottomMargin = Unit.FromMillimeter(7);

Table table = sec.AddTable();
table.AddColumn(Unit.FromMillimeter(196));

Row row = table.AddRow();
row.HeightRule = RowHeightRule.Exactly;
row.Height = Unit.FromPoint(70);

row.Cells[0].AddParagraph("TABLE TEXT");

Color blackColor = new Color(0, 0, 0);
row.Shading.Color = blackColor;

在结果PDF中,左边距为5.95mm,上边距为6.86mm。

image of result PDF

1 个答案:

答案 0 :(得分:0)

您应该将table.Rows.LeftIndent设置为0.这会增加左边距。

默认情况下,表格中的文字正好是7毫米(在您的情况下) - 因此,如果您从表格的边缘进行测量,则左边距会略小。

table.Rows.LeftIndent设置为0会使表格的边缘达到7毫米。

也许您必须将表格边框的宽度设置为0才能获得精确的7毫米。边框在两侧绘制,因此边框宽度的一半将从顶部和左边距中减去。