Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
575
Overlay text on top of an image
posted

Is there a way to overlay some text over top of an image (without using a Site object) using Infragistics Document engine?

 I would want the background of the text to be transparent, such that I could see the image behind the text.

Parents
No Data
Reply
  • 37774
    posted

    There's not a really simple way to do this, since without the ISite object, everything will be positioned sequentially.  What you could do is create a new Background object on the IText element that you are adding your content to.  In the constructor for the Background, you would pass in an instance of a class that you write that implements IDrawing, so you can draw whatever you want into the background, such as:

    Report r = new Report();
    IText text = r.AddSection().AddText();
    text.Background = new Background(Infragistics.Documents.Graphics.Brushes.White, new MyDrawing());
    text.AddContent("This is some text");

    r.Publish("Test.pdf", FileFormat.PDF);

    private class MyDrawing : IDrawing
    {
        public void OnDraw(Infragistics.Documents.Graphics.IGraphics graphics, float x, float y, float width, float height)
        {
            Infragistics.Documents.Graphics.Image image = new Infragistics.Documents.Graphics.Image("wave_1280_1024.jpg");
            graphics.DrawImage(image, x, y, width, height);
        }
    }

    Naturally, you would have to replace the name of the image with whatever is appropriate.  You also might want to center the image, not stretch it, etc, but with the IDrawing interface you have a lot more flexibility.

    -Matt 

Children