Setting Text Color Using PdfProcessing
Environment
Version | Product | Author |
---|---|---|
2025.2.520 | RadPdfProcessing | Desislava Yordanova |
Description
Learn how to change the text color of a Block.
Solution
To set the text color of a block, use the FillColor
property of the Block's GraphicProperties
. This property determines the color used for rendering the content elements of a block. To apply the change only to specific text, use the SaveGraphicProperties()
and RestoreGraphicProperties()
methods. These methods allow you to apply a temporary change and revert to the previous settings.
Example Code
RadFixedDocument document = new RadFixedDocument();
RadFixedPage page = document.Pages.AddPage();
FixedContentEditor editor = new FixedContentEditor(page);
// Create a block to add styled content
Block infoBlock = new Block();
// Save current graphic properties
infoBlock.SaveGraphicProperties();
// Set the FillColor for the text
infoBlock.GraphicProperties.FillColor = new RgbColor(255, 10, 10);
infoBlock.InsertText("Telerik Document Processing: ");
// Restore previous graphic properties
infoBlock.RestoreGraphicProperties();
infoBlock.InsertLineBreak();
infoBlock.InsertText("RadPdfProcessing");
infoBlock.InsertLineBreak();
// Position and draw the block
editor.Position.Translate(100, 100);
editor.DrawBlock(infoBlock);
// Export the document
string fileName = $"{Guid.NewGuid()}.pdf";
File.Delete(fileName);
PdfFormatProvider provider = new PdfFormatProvider();
using Stream stream = File.OpenWrite(fileName);
provider.Export(document, stream, TimeSpan.FromSeconds(10));
Process.Start(new ProcessStartInfo() { UseShellExecute = true, FileName = fileName });