I am using PDFsharp to generate a PDF document from scratch. I am trying to write text on top of a gradient filled rectangle. After generating the document, the gradient appears on top of the text rendering the text completely hidden.
using (var document = new PdfDocument())
{
var page = document.AddPage();
var graphics = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
graphics.SmoothingMode = XSmoothingMode.HighQuality;
var bounds = new XRect(graphics.PageOrigin, graphics.PageSize);
graphics.DrawRectangle(
new XLinearGradientBrush(
bounds,
XColor.FromKnownColor(XKnownColor.Red),
XColor.FromKnownColor(XKnownColor.White),
XLinearGradientMode.ForwardDiagonal),
bounds);
graphics.DrawString(
"Hello World!",
new XFont("Arial", 20),
XBrushes.Black,
bounds.Center,
XStringFormats.Center);
document.Save("test.pdf");
document.Close();
}
How can I make the text render on top of the rectangle?
I find that any images I draw later will appear on top of the rectangle. It’s only text that hides behind.