|
| 1 | +--- |
| 2 | +title: Setting Text Color Using PdfProcessing |
| 3 | +description: Learn how to set/change text color using the Telerik PdfProcessing library. |
| 4 | +type: how-to |
| 5 | +page_title: How to Set Text Color Using PdfProcessing |
| 6 | +meta_title: How to Set Text Color Using PdfProcessing |
| 7 | +slug: pdfprocessing-text-color |
| 8 | +tags: pdf, processing, text, color, block, color, graphic, set, change |
| 9 | +res_type: kb |
| 10 | +ticketid: 1695311 |
| 11 | +--- |
| 12 | + |
| 13 | +## Environment |
| 14 | + |
| 15 | +| Version | Product | Author | |
| 16 | +| ---- | ---- | ---- | |
| 17 | +| 2025.2.520| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)| |
| 18 | + |
| 19 | +## Description |
| 20 | + |
| 21 | +Learn how to change the text color of a [Block]({%slug radpdfprocessing-editing-block%}). |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +## Solution |
| 26 | + |
| 27 | +To set the text color of a block, use the `FillColor` property of the [Block]({%slug radpdfprocessing-editing-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. |
| 28 | + |
| 29 | +### Example Code |
| 30 | + |
| 31 | +```csharp |
| 32 | +RadFixedDocument document = new RadFixedDocument(); |
| 33 | +RadFixedPage page = document.Pages.AddPage(); |
| 34 | +FixedContentEditor editor = new FixedContentEditor(page); |
| 35 | + |
| 36 | +// Create a block to add styled content |
| 37 | +Block infoBlock = new Block(); |
| 38 | + |
| 39 | +// Save current graphic properties |
| 40 | +infoBlock.SaveGraphicProperties(); |
| 41 | + |
| 42 | +// Set the FillColor for the text |
| 43 | +infoBlock.GraphicProperties.FillColor = new RgbColor(255, 10, 10); |
| 44 | +infoBlock.InsertText("Telerik Document Processing: "); |
| 45 | + |
| 46 | +// Restore previous graphic properties |
| 47 | +infoBlock.RestoreGraphicProperties(); |
| 48 | +infoBlock.InsertLineBreak(); |
| 49 | +infoBlock.InsertText("RadPdfProcessing"); |
| 50 | +infoBlock.InsertLineBreak(); |
| 51 | + |
| 52 | +// Position and draw the block |
| 53 | +editor.Position.Translate(100, 100); |
| 54 | +editor.DrawBlock(infoBlock); |
| 55 | + |
| 56 | +// Export the document |
| 57 | +string fileName = $"{Guid.NewGuid()}.pdf"; |
| 58 | +File.Delete(fileName); |
| 59 | +PdfFormatProvider provider = new PdfFormatProvider(); |
| 60 | +using Stream stream = File.OpenWrite(fileName); |
| 61 | +provider.Export(document, stream, TimeSpan.FromSeconds(10)); |
| 62 | + |
| 63 | +Process.Start(new ProcessStartInfo() { UseShellExecute = true, FileName = fileName }); |
| 64 | +``` |
| 65 | + |
| 66 | +## See Also |
| 67 | + |
| 68 | +- [Text and Graphic Properties in PdfProcessing]({%slug radpdfprocessing-editing-text-and-graphic-properties%}) |
0 commit comments