Search code examples
c#pdfsharpmigradoc

MigraDoc picture on a picture on a pcture


I have a cover page, where I have a picture which fills most of the page.

On that picture I have placed another picture which is dynamic, but onto those two pictures I need to place one more small logo picture, and that’s where it goes wrong (logo picture ends up in bottom right border of second layer picture).

First layer picture

var myImage = section.AddImage(Server.MapPath("~/Content/Images/Forside.png"));
            myImage.Height = "23cm";
            myImage.Width = "21cm";
            myImage.RelativeVertical = RelativeVertical.Page;
            myImage.RelativeHorizontal = RelativeHorizontal.Page;
            myImage.WrapFormat.Style = WrapStyle.Through;

Second layer picture

MigraDoc.DocumentObjectModel.Shapes.Image image1 = section.AddImage(@model.UrlImage);
                image1.Width = "15.5cm";
                image1.Height = "8cm";

                image1.RelativeHorizontal = RelativeHorizontal.Character;
                image1.RelativeVertical = RelativeVertical.Line;
                image1.Left = Unit.FromCentimeter(0.2);
                image1.Top = Unit.FromCentimeter(8.6);

Third layer picture

    var image4 = section.AddImage(Server.MapPath("~/Content/Images/sun icon.png"));
    image4.RelativeHorizontal = RelativeHorizontal.Character;
    image4.RelativeVertical = RelativeVertical.Line;
    image4.WrapFormat.DistanceLeft = Unit.FromCentimeter(0.2);
    image4.WrapFormat.DistanceTop = Unit.FromCentimeter(6.6);
    image4.WrapFormat.Style = WrapStyle.Through;

Any ideas?


Solution

  • Use this code also for the 3rd layer:

    myImage.RelativeVertical = RelativeVertical.Page;
    myImage.RelativeHorizontal = RelativeHorizontal.Page;
    

    Calculate the absolute position for the 3rd layer picture, that should work.