Free Support Forum -

Z-Index not respected TextFragment over Rectangle

Hi there

Im using the following code to add a rectangle to a page and place a TextFragment over it. I expect to see the TextFragement being drawn in front of the graph object but the text is behing the object and it seems, that the z-index is not respected. Is there a way how I can force TextFragement to be in front of something else?

I also tried to use the concept of adding the text to the rectangle, but that approach has some shortcomings like text cannot be properly placed in the rectangle and that the alpha channel is also applied to the text.


//Define the page
Document doc = new Document();
Page page = doc.Pages.Add();
page.PageInfo.Margin = new MarginInfo(0, 0, 0, 0);

//Define the parameters
marginLeft = 40,
marginRight = 40,
pageW = (float)page.PageInfo.Width,
pageH = (float)page.PageInfo.Height,
graphH = 26;

int fontSizeL = 18,
fontSizeS = 12;

Font font = FontRepository.FindFont(“Arial”);

//Adding the rectangle
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(pageW, graphH);
graph.IsChangePosition = false;
graph.Left = 0;
graph.Top = 0;

Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(0, 0, pageW, graphH);
rect.GraphInfo.FillColor = Color.FromArgb(217, 240, 213, 144);
rect.GraphInfo.Color = Color.Transparent;

graph.ZIndex = 0;

TextFragment textLeft = new TextFragment(“I should be in front of the graph object”);
textLeft.HorizontalAlignment = HorizontalAlignment.Left;
textLeft.TextState.Font = font;
textLeft.TextState.FontSize = fontSizeL;
textLeft.Position = new Position(marginLeft, pageH - graphH + (graphH -fontSizeL)/2);
textLeft.ZIndex = 1;

//Set right text, measure the string and calculate x-Positions
string tRight = “Me too, but smaller”;
TextState tsRight = new TextState
Font = font,
FontSize = fontSizeS

float tRight_Width = (float)tsRight.MeasureString(tRight);

TextFragment textRight = new TextFragment(tRight);
textRight.HorizontalAlignment = HorizontalAlignment.Right;
textRight.TextState.Font = FontRepository.FindFont(“Arial”);
textRight.TextState.FontSize = fontSizeS;
textRight.Position = new Position(pageW - marginRight - tRight_Width, pageH - graphH + (graphH - fontSizeS) / 2);
textRight.ZIndex = 1;

//Adding stuff to pdf
TextBuilder builder = new TextBuilder(page);


doc.Save(dataDir + “OutputTextOverShape.pdf”);
Process.Start(dataDir + “OutputTextOverShape.pdf”);

OutputTextOverShape.pdf (32.9 KB)

Many thanks for your help


Thank you for contacting support.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFNET-45473 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.