将单元格内的图像向右对齐不起作用

问题描述 投票:-2回答:3

我需要在页眉上对齐右侧的图像。这是我的代码:

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;

但是它总是在左边,请帮忙吗?

pdfsharp migradoc
3个回答
6
投票

我知道有点晚了但是您必须将图像包装在一个段落中。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);

我在使用上面的代码/链接时遇到了同样的问题。


0
投票

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;行是多余的,但无害。


-1
投票

如果您那样做,它将起作用:

row.Cells[1].AddParagraph().AddImage(fileName);
row.Cells[1].Format.Alignment = ParagraphAlignment.Right;
© www.soinside.com 2019 - 2024. All rights reserved.