I have a solution that requires shaded regions to be placed in the background (behind) of text.
I am unable to manage the Zorder of the objects using the Zindex property when I am creating objects. (the text is obfuscated by the filled path regions)
Here is a sample snippet of code . this code writes shaded paths and then writes text within the shaded path region.
public static void ExecValidateZorder()
{
Aspose.Pdf.Document doc = new Document();
Aspose.Pdf.Page p = doc.Pages.Add();
p.PageInfo.Height = 11.0f * 72.0f;
p.PageInfo.Width = 8.5f * 72.0f;
p.PageInfo.Margin.Bottom = 0.0f;
p.PageInfo.Margin.Top = 0.0f;
p.PageInfo.Margin.Left = 0.0f;
p.PageInfo.Margin.Right = 0.0f;
WriteShadedRect(Convert.ToSingle( p.PageInfo.Width),Convert.ToSingle( p.PageInfo.Height), 100, 100, 180, 110, 170, 300, 50, 310, p.Paragraphs);
WriteShadedRect(Convert.ToSingle(p.PageInfo.Width), Convert.ToSingle(p.PageInfo.Height), 10, 20, 400,15, 420, 110, 5, 200, p.Paragraphs);
WriteMultiLineLText(p,
“THIS STRING OF TEXT WILL BE WRAPPED TO MULTIPLE LINES TO FIT INTO A MULTI-LINE TEXT CONFIGURATION”, 120, 120, 150, 100);
doc.Save(“C:\\temp\zordertext.pdf”);
}
private static void WriteShadedRect(float pageWidth, float pageHeight, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Aspose.Pdf.Paragraphs ps)
{
var g = new Graph(pageWidth, pageHeight)
{
IsChangePosition = false,
ZIndex = 0,
};
var newPath = new Aspose.Pdf.Drawing.Path();
newPath.Shapes.Add(new Aspose.Pdf.Drawing.Line(new[]
{
x1,y1,x2,y2,x3,y3,x4,y4,x1,y1
}));
newPath.GraphInfo.Color = Color.Transparent;
newPath.GraphInfo.FillColor = Color.FromArgb(241, 241, 241);
g.Shapes.Add(newPath);
ps.Add(g);
}
private static void WriteMultiLineLText(Page p, string text, float x1, float y1, float width, float height)
{
var txtBldr = new TextBuilder§;
var txtPara = new TextParagraph
{
SubsequentLinesIndent = 0.0f,
FormattingOptions = {WrapMode = TextFormattingOptions.WordWrapMode.ByWords},
Rectangle = new Aspose.Pdf.Rectangle(x1, y1, x1 + width, y1 + height)
};
Aspose.Pdf.Text.TextFragment tf = new TextFragment(text) { ZIndex = 2 };
tf.TextState.Font = FontRepository.FindFont(“Arial”);
tf.TextState.FontSize = 12.4f;
tf.TextState.ForegroundColor = Color.Black;
tf.TextState.FontStyle = FontStyles.Regular;
tf.TextState.HorizontalAlignment = HorizontalAlignment.Center;
tf.TextState.HorizontalScaling = 90.5f;
tf.TextState.LineSpacing = 1.0f;
txtPara.AppendLine(tf);
txtBldr.AppendParagraph(txtPara);
}
I have attached the resulting pdf from this code.
I have also attached the resulting pdf from some more complex code that exhibits the same behavior. This code creates reports and utilzes shaded regions to highlight content.
I am in the process of replacing an existing pdf solution with Aspose. I have attached a pdf copy of what the pdf should look like
zordertext.pdf (48.4 KB)
Reportoutput.pdf (62.5 KB)
Reportoutput_itext.pdf (297.3 KB)
[/quote]