[英]How to put images next to each other in a PDF using MigraDoc (C#)
I have a table cell where I want to put two images next to each other. 我有一个表格单元格,要在其中放置两个图像。 Can't seem to get it right.
似乎无法正确解决。
var imageIndex = 0;
foreach (var fileName in fileNames)
{
var image = new Image(fileName)
{
WrapFormat =
{
DistanceTop = 10,
DistanceRight = 10,
DistanceLeft = imageIndex * imageSize
},
Width = imageSize,
Height = imageSize
};
row.Cells[0].Add(image);
imageIndex++;
}
MigraDoc samples advert using RelativeHorizontal/RelativeVertical, however I can't get to understand how. MigraDoc示例使用RelativeHorizontal / RelativeVertical进行广告,但是我不了解如何做。 There are only examples with image and text, and no example with 2 images.
只有带有图像和文本的示例,没有带有2张图像的示例。
The most simple solution: add a paragraph to the table cell, add both images to the paragraph and add non-breaking spaces between them for the distance. 最简单的解决方案:将一个段落添加到表格单元格,将两个图像添加到该段落,并在它们之间添加不间断的空格以保持距离。
This works fine if both images have (nearly) the same height. 如果两个图像的高度(几乎)相同,则效果很好。
In this case images will be handled by the normal text layouter. 在这种情况下,图像将由常规文本布局器处理。
Another simple solution: create a separate cell for each image. 另一个简单的解决方案:为每个图像创建一个单独的单元格。 You can use
MergeRight
in other rows if you don't want the extra cell visible there. 如果您不想在此处看到多余的单元格,则可以在其他行中使用
MergeRight
。
You can take the images out of the normal layout flow using RelativeHorizontal
and RelativeVertical
, but this makes things a bit complicated. 您可以使用
RelativeHorizontal
和RelativeVertical
将图像从常规布局流程中移出,但这会使事情有些复杂。 AFAIK you have to set image.WrapFormat.Style = WrapStyle.Through;
AFAIK,您必须设置
image.WrapFormat.Style = WrapStyle.Through;
to make this work. 使这项工作。 But then you also have to take care that text and images do not overlap.
但是,然后您还必须注意文本和图像不会重叠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.