This is a migrated thread and some comments may be shown as answers.

Set Text Colour in RadFixedDocument Block

2 Answers 155 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
kencox
Top achievements
Rank 1
kencox asked on 15 Apr 2018, 01:56 AM

Hi folks,

In the code below, how do I set the text colour for text "INVOICE TO" (line 10) to gray? This is using RadFixedDocument.  

The Block object's TextProperties has a HighlightColor property but not a Color property.

As you can see in the code below, the block is inside a cell within a table row within a table.

Thanks for any pointers.

Ken

01.Table addressInfoTable = new Table();
02.addressInfoTable.LayoutType = TableLayoutType.FixedWidth;
03.TableRow infoToRow = addressInfoTable.Rows.AddTableRow();
04.TableCell infoToCell = infoToRow.Cells.AddTableCell();
05.infoToCell.PreferredWidth = 350;
06.Block infoBlock = infoToCell.Blocks.AddBlock();
07.infoBlock.HorizontalAlignment = HorizontalAlignment.Left;
08.//       infoBlock.TextProperties.HighlightColor = new RgbColor(0, 0, 255);
09.//       infoBlock.BackgroundColor = new RgbColor(255, 10, 10);
10.infoBlock.InsertText("INVOICE TO");
11.infoBlock.InsertLineBreak();
12.infoBlock.InsertText(invoice.Payer.FirstName() + " " + invoice.Payer.LastName());
13.infoBlock.InsertLineBreak();

2 Answers, 1 is accepted

Sort by
0
Accepted
Tanya
Telerik team
answered on 18 Apr 2018, 12:30 PM
Hi Ken,

Thank you for sharing the code.

To change the forecolor of the text, you will need to set the FillColor property of GraphicProperties, as this color is used while drawing the content elements of a Block. You can use the SaveGraphicProperties() and RestoreGraphicProperties() methods to apply the change only to the desired text and then return to the previously used settings. Here is an example in code:

infoBlock.SaveGraphicProperties();
infoBlock.GraphicProperties.FillColor = new RgbColor(255, 10, 10);
infoBlock.InsertText("INVOICE TO");
infoBlock.RestoreGraphicProperties();
infoBlock.InsertLineBreak();
infoBlock.InsertText(invoice.Payer.FirstName() + " " + invoice.Payer.LastName());
infoBlock.InsertLineBreak();

Hope this is helpful.

Regards,
Tanya
Progress Telerik

0
kencox
Top achievements
Rank 1
answered on 18 Apr 2018, 02:53 PM

Perfect!

Thanks!

en

Tags
PdfProcessing
Asked by
kencox
Top achievements
Rank 1
Answers by
Tanya
Telerik team
kencox
Top achievements
Rank 1
Share this question
or