Hello guys, thank you for an awesome PDF lib, really appreciated.
As for this bugreport:
The following code produces a solid red rectangle, without gradient to transparent as I hoped for.
The code can be run as console app (copy paste console app), .net6.0, pdfsharp prev 4.
Checked in chrome, edge and sumatraPdf.
Am I missing something?
Code:
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using System.IO;
public static void DrawGradientRectangle(string filePath)
{
using (PdfDocument document = new PdfDocument())
{
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XRect rect = new XRect(50, 50, 250, 100); // x, y, width, height
// Create a red to transparent gradient brush
XLinearGradientBrush brush = new XLinearGradientBrush(
rect,
XColor.FromArgb(255, 255, 0, 0), // Solid Red
XColor.FromArgb(0, 255, 0, 0), // Transparent Red
XLinearGradientMode.Horizontal
);
// Draw the rectangle with the gradient brush
gfx.DrawRectangle(brush, rect);
// Save the document
document.Save(filePath);
}
}
// Call the function and provide the path to save the PDF
DrawGradientRectangle("GradientRectangle.pdf");