Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions knowledge-base/pdfprocessing-text-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Setting Text Color Using PdfProcessing
description: Learn how to set/change text color using the Telerik PdfProcessing library.
type: how-to
page_title: How to Set Text Color Using PdfProcessing
meta_title: How to Set Text Color Using PdfProcessing
slug: pdfprocessing-text-color
tags: pdf, processing, text, color, block, color, graphic, set, change
res_type: kb
ticketid: 1695311
---

## Environment

| Version | Product | Author |
| ---- | ---- | ---- |
| 2025.2.520| RadPdfProcessing |[Desislava Yordanova](https://www.telerik.com/blogs/author/desislava-yordanova)|

## Description

Learn how to change the text color of a [Block]({%slug radpdfprocessing-editing-block%}).

![Change Text Block's ForeColor ><](images/pdfprocessing-text-color.png)

## Solution

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.

### Example Code

```csharp
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 });
```

## See Also

- [Text and Graphic Properties in PdfProcessing]({%slug radpdfprocessing-editing-text-and-graphic-properties%})
1 change: 1 addition & 0 deletions libraries/radpdfprocessing/editing/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,4 @@ The code in __Example 9__ splits a block in two. The first will contains text "H
* [How to Measure Text in WordsProcessing .NET Framework]({%slug wordsprocessing-measure-text-netframework%})
* [How to Measure Text in WordsProcessing .NET Standard]({%slug wordsprocessing-measure-text-netstandard%})
* [How to Generate a PDF Document from Images with FixedContentEditor]({%slug pdf-from-images-with-fixedcontenteditor%})
* [How to Change Text Color Using PdfProcessing]({%slug pdfprocessing-text-color%})
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ Both Text and Graphic properties contain methods that can preserve and restore t
* [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%})
* [Block]({%slug radpdfprocessing-editing-block%})
* [Changing Block's Text Color in PDF Documents Using RadPdfProcessing]({%slug change-text-color-pdf-radpdfprocessing%})
* [How to Change Text Color Using PdfProcessing]({%slug pdfprocessing-text-color%})