We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Z-Index ignored over FloatingBox and TextBuilder

Hi there

I’m trying to overlay a text paragraph on top of a floating box. Setting the z-index seems to have no effect. From what I understand in the documentation, setting z-index to a negative number ought to put the floating box behind the text paragraph. What am I missing? Below is my code.

Many thanks, Brett

    public static void CreateZIndexSample(Stream stream)
    {
        SetLicense();

        var document = new Document();
        var page = document.Pages.Add();

        // draw the filled box
        var width = 100f;
        var height = 100f;
        var left = 100f;
        var top = 100f;

        var box = new FloatingBox { Left = left, Top = top, ZIndex = -1 };
        var graph = new Aspose.Pdf.Drawing.Graph(width, height);

        var shape = new Aspose.Pdf.Drawing.Rectangle(0, 0, width, height)
        {
            GraphInfo = new GraphInfo
            {
                Color = Color.Black,
                FillColor = Color.Blue
            }
        };

        graph.Shapes.Add(shape);
        box.Paragraphs.Add(graph);
        page.Paragraphs.Add(box);

        // add the text
        var builder = new TextBuilder(page);
        var fragment = new TextFragment("Hello, world!");
        fragment.TextState.Font = FontRepository.FindFont("Helvetica");
        fragment.TextState.FontSize = 20;
        fragment.ZIndex = 1;

        var paragraph = new TextParagraph
        {
            Position = new Position(page.PageInfo.Margin.Left + left + 20f, page.PageInfo.PureHeight - top),
        };

        paragraph.AppendLine(fragment);
        builder.AppendParagraph(paragraph);

        document.Save(stream);
    }

@brettfisher

Thanks for contacting support.

I have tested the scenario and was able to notice that text was not showing above the rectangle. Hence, for the purpose of investigation, I have logged this issue as PDFNET-43130 in our issue tracking system. We will further look into the details of the issue and keep you informed with the status. Please be patient and spare us little time.

Moreover, I have also tried to add text through another FloatingBox and it appeared over the Rectangle as expected. Please check following code snippet which I have tried. For your reference, I have attached an output as well.

var document = new Document();
var page = document.Pages.Add();

// draw the filled box
var width = 100f;
var height = 100f;
var left = 100f;
var top = 100f;

var box = new FloatingBox { Left = left, Top = top, ZIndex = 1 };
var graph = new Aspose.Pdf.Drawing.Graph(width, height);

var shape = new Aspose.Pdf.Drawing.Rectangle(0, 0, width, height)
{
 GraphInfo = new GraphInfo
 {
  Color = Color.Black,
  FillColor = Color.Blue
 }
};

graph.Shapes.Add(shape);
box.Paragraphs.Add(graph);
page.Paragraphs.Add(box);

// add the text
var fragment = new TextFragment("Hello, world!");
fragment.TextState.Font = FontRepository.FindFont("Helvetica");
fragment.TextState.FontSize = 20;

var box2 = new FloatingBox { Left = left, Top = top, ZIndex = 2 };
box2.Paragraphs.Add(fragment);
page.Paragraphs.Add(box2);
document.Save(dataDir + "ZIndexIssue.pdf"); 

ZIndexIssue.pdf (1.9 KB)

We are sorry for this inconvenience.