954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Change string color

I have a string "Hello World"

I want to change the color of Hello to red using the setCMYKColorFillF function. I'm writing the string to a PDF file


I know I'll use to write to the pdf:

private PdfContentByte WriteTxt = null;
WriteTxt.setCMYKColorFillF(float Cyan, float Magenta, float Yellow, float Black);
WriteTxt.showTextAligned(int Align ,"Hello World", float x Position, float y Position, 0f);

michael.ngobeni
Newbie Poster
20 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Is there a question in there somewhere?

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 
Is there a question in there somewhere?


Oh please. I was so excited when I saw that there is at least 1 response to my post.

Anyway since if I write:
WriteTxt.setCMYKColorFillF(00, 00, 00, 00);

The output will be "Hello World" in black, but I want to change it to:
Hello World

My question is "How do I do make Hello red and leave the rest as it is?"

michael.ngobeni
Newbie Poster
20 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Do Hello in red, then world in black.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 
Do Hello in red, then world in black.

That's now how I wanted to do it.

I know iwould have to do this

WriteTxt.setCMYKColorFillF(00, 99, 100, 00);
WriteTxt.showTextAligned(0 ,"Hello", 100, 20, 0f);

WriteTxt.setCMYKColorFillF(00, 00, 00, 00);
WriteTxt.showTextAligned(0 ,"World", 120, 20, 0f);

The problem with setCMYKColorFillF is that u can't specify what text of string you want to change.

It should be like WriteTxt.setCMYKColorFillF(00, 00, 00, 00, "World") or something like that.

michael.ngobeni
Newbie Poster
20 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Could you write a small class that extends PdfContentByte and write a new method with the parameters that you want to pass that simply calls the original setCMYKColorFillF method followed by the showTextAligned method? Then you can call that new method as you need.

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

That's now how I wanted to do it.

I know iwould have to do this

WriteTxt.setCMYKColorFillF(00, 99, 100, 00); WriteTxt.showTextAligned(0 ,"Hello", 100, 20, 0f);

WriteTxt.setCMYKColorFillF(00, 00, 00, 00); WriteTxt.showTextAligned(0 ,"World", 120, 20, 0f);

The problem with setCMYKColorFillF is that u can't specify what text of string you want to change.

It should be like WriteTxt.setCMYKColorFillF(00, 00, 00, 00, "World") or something like that.


Well, I'm sorry. There are a lot of things I don't like, that doesn't mean I don't have to do them. darkagn has it correct, create one of your own. Or, search the library you're using (I don't know which one it is) and see if there is a another method (or simply an overloaded version of the same) that does what you want, if not, as already said, implement a "convenience" method, yourself. If the method your using doesn't allow what you want, directly, then you aren't going to be able change that (you could always suggest an enhancement to whoever produced the library, though).

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

One way to do this, will be to embed it in html code. I.e.
String helloStrng = " Hello

azinyue
Newbie Poster
1 post since Sep 2010
Reputation Points: 10
Solved Threads: 0
 
One way to do this, will be to embed it in html code. I.e. String helloStrng = " Hello
masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You