Add Transparent Text in PDF using C# | Aspose.PDF for .NET

@asad.ali

the following will produce text fragments… but if the text fragment font color is solid black, it looks like the alpha from the foreground color is used for the background color

var page = document.Pages.Add();
page.Background = Aspose.Pdf.Color.Yellow;
for (int p = 1; p < 17; p++)
{
var alpha = (p - 1) * 16;
Color systemColor = System.Drawing.Color.FromArgb(alpha, 0, 0, 255);
var asposeColor = Aspose.Pdf.Color.FromArgb(systemColor.A, systemColor.R, systemColor.G, systemColor.B);

                var textFragment =
                    new TextFragment($"This text background is Blue at {systemColor.A}:{asposeColor.A} alpha");
                Assert.That(systemColor.A, Is.EqualTo(alpha));
                textFragment.TextState.BackgroundColor = asposeColor;
                textFragment.TextState.ForegroundColor =
                    Aspose.Pdf.Color.FromArgb(254, Color.Black.R, Color.Black.G, Color.Black.B);
                page.Paragraphs.Add(textFragment);

                textFragment =
                    new TextFragment(
                        $"This text foreground and background is Blue at {systemColor.A}:{asposeColor.A} alpha");
                textFragment.TextState.BackgroundColor = asposeColor;
                textFragment.TextState.ForegroundColor = asposeColor;
                page.Paragraphs.Add(textFragment);
            }

@johne42

Thanks for sharing the working sample code. We were able to reproduce this behavior of the API and have updated the ticket information accordingly. We will surely investigate the issue from this perspective and let you know as soon as it is resolved. Please be patient and spare us some time.

we are sorry for the inconvenience.

Thank you for your attention to this issue… would love to have this working

1 Like

Hi Guys,

Two years on, do you have any update on this issue? When is it going to be resolved or where is it in the queue?

@vitro

The issue currently under that phase of the investigation and soon it is expected to be complete. We will be sharing updates soon with you. Please spare us little time. We apologize for the delay and the inconvenience.

The issues you have found earlier (filed as PDFNET-49739) have been fixed in Aspose.PDF for .NET 23.3.