Skip to content

Commit 358875e

Browse files
authored
Merge pull request #605 from telerik/new-kb-pdfprocessing-text-color-c70929ba21a04d7d8ffd9164b6472789
Added new kb article pdfprocessing-text-color
2 parents 191f2a8 + 58a956f commit 358875e

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
5.46 KB
Loading
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
![Change Text Block's ForeColor ><](images/pdfprocessing-text-color.png)
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%})

libraries/radpdfprocessing/editing/block.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,4 @@ The code in __Example 9__ splits a block in two. The first will contains text "H
311311
* [How to Measure Text in WordsProcessing .NET Framework]({%slug wordsprocessing-measure-text-netframework%})
312312
* [How to Measure Text in WordsProcessing .NET Standard]({%slug wordsprocessing-measure-text-netstandard%})
313313
* [How to Generate a PDF Document from Images with FixedContentEditor]({%slug pdf-from-images-with-fixedcontenteditor%})
314+
* [How to Change Text Color Using PdfProcessing]({%slug pdfprocessing-text-color%})

libraries/radpdfprocessing/editing/text-and-graphic-properties.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ Both Text and Graphic properties contain methods that can preserve and restore t
129129
* [FixedContentEditor]({%slug radpdfprocessing-editing-fixedcontenteditor%})
130130
* [Block]({%slug radpdfprocessing-editing-block%})
131131
* [Changing Block's Text Color in PDF Documents Using RadPdfProcessing]({%slug change-text-color-pdf-radpdfprocessing%})
132+
* [How to Change Text Color Using PdfProcessing]({%slug pdfprocessing-text-color%})

0 commit comments

Comments
 (0)