LIvanov
LIvanov

Reputation: 1336

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. There are only examples with image and text, and no example with 2 images.

Upvotes: 1

Views: 1110

Answers (1)

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.

You can take the images out of the normal layout flow using RelativeHorizontal and RelativeVertical, but this makes things a bit complicated. AFAIK you have to set image.WrapFormat.Style = WrapStyle.Through; to make this work. But then you also have to take care that text and images do not overlap.

Upvotes: 1

Related Questions