我需要在页眉上对齐右侧的图像。这是我的代码:
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("8cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = table.AddColumn("4cm");
column.Format.Alignment = ParagraphAlignment.Right;
eRow.Cells[0].AddParagraph("Some text");
eRow.Cells[1].AddParagraph("Some text");
eRow.Cells[2].Format.Alignment = ParagraphAlignment.Right;
image = eRow.Cells[2].Elements.AddImage(imagePath);
image.LockAspectRatio = false;
image.Width = Unit.FromInch(0.16);
image.Height = Unit.FromInch(0.09);
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
但是它总是在左边,请帮忙吗?
我知道有点晚了但是您必须将图像包装在一个段落中。http://forum.pdfsharp.net/viewtopic.php?f=2&t=158
类似(我使用了部分代码)
Section section = document.AddSection();
table = section.Headers.Primary.AddTable();
var column = table.AddColumn("5cm");
//I assume eRow is just a row added to your table
var eRow = table.AddRow();
var paragraph = eRow.Cells[0].AddParagraph();
//set the alignment on the paragraph object
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.AddImage(imagePath);
我在使用上面的代码/链接时遇到了同样的问题。
行
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
从逻辑上将图像从单元中取出。这将创建一个图像,该图像可以显示在页面上的任何位置,而不仅仅是单元格内部。
也许只要删除这五行就可以了。如果将Paragraph
添加到Cell
并将Image
添加到单元格,则可能会起作用。
如果您提供了MCVE,如果我的建议有效,我会尝试的。但是您只显示一个代码片段。
image.LockAspectRatio = false;
行是多余的,但无害。
如果您那样做,它将起作用:
row.Cells[1].AddParagraph().AddImage(fileName);
row.Cells[1].Format.Alignment = ParagraphAlignment.Right;