We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to add text with Gradient Fill in PDF using C# with Aspose.PDF for .NET

Hi,

Is it supported, adding gradient filled text in existing PDF document with Aspose.PDF? I’m using this code:

using PdfDocument = Aspose.Pdf.Document;
PdfDocument pdfDocument = new PdfDocument(“input.pdf”);
Page pdfPage = (Page)pdfDocument.Pages[1];
//Using Arabic Text
TextFragment textFragment = new TextFragment(“استمارة طلب الاشتراك في خدمات”);
textFragment.Position = new Position(100,400);
textFragment.TextState.FontSize = 18;
//Using custom OTF Font
textFragment.TextState.Font = FontRepository.FindFont(“GESSTextBold”);
textFragment.TextState.Font.IsEmbedded = true;
//HOW TO SET GRADIENT FILL FOR FONT FOREGROUND COLOR???
//textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
TextBuilder textBuilder = new TextBuilder(pdfPage);
textBuilder.AppendText(textFragment);
pdfDocument.Save(“output2.pdf”);

I have also attached the OTF Font we are using (rename -> delete .txt from filename).

Thanks

Hi Igor,


Thanks for your inquiry. I am afraid currently Aspose.Pdf does not provide support to add text with gradient fill, so I have logged a ticket PDFNET-41246 in our issue tracking system for further investigation and implementation. We will notify you as soon as the feature request is implement.

We are sorry for the inconvenience.

Best Regards,

@Andonovski

We would like to share with you that we have implemented support of gradient fill for text adding scenarios in Aspose.PDF for .NET. Setting gradient fill to text fragment (segment) foreground color is going to be operable with Aspose.PDF.

Please use the following code to set foreground color with gradient fill:

//Create new color with pattern colorspace
textFragment.TextState.ForegroundColor = new Aspose.Pdf.Color
{
//Set PatternColorSpace to linear gradient with red starting color and blue ending color
PatternColorSpace = new GradientAxialShading(Color.Red, Color.Blue)
};