Change string color

Reply

Join Date: Dec 2006
Posts: 20
Reputation: michael.ngobeni is an unknown quantity at this point 
Solved Threads: 0
michael.ngobeni michael.ngobeni is offline Offline
Newbie Poster

Change string color

 
0
  #1
Jan 7th, 2008
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);
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,638
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 283
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: Change string color

 
0
  #2
Jan 7th, 2008
Is there a question in there somewhere?
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 20
Reputation: michael.ngobeni is an unknown quantity at this point 
Solved Threads: 0
michael.ngobeni michael.ngobeni is offline Offline
Newbie Poster

Re: Change string color

 
0
  #3
Jan 7th, 2008
Originally Posted by masijade View Post
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?"
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,638
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 283
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: Change string color

 
0
  #4
Jan 7th, 2008
Do Hello in red, then world in black.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 20
Reputation: michael.ngobeni is an unknown quantity at this point 
Solved Threads: 0
michael.ngobeni michael.ngobeni is offline Offline
Newbie Poster

Re: Change string color

 
0
  #5
Jan 7th, 2008
Originally Posted by masijade View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 923
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 130
darkagn's Avatar
darkagn darkagn is offline Offline
Posting Shark

Re: Change string color

 
0
  #6
Jan 7th, 2008
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.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,638
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 283
Moderator
masijade's Avatar
masijade masijade is offline Offline
Posting Maven

Re: Change string color

 
1
  #7
Jan 7th, 2008
Originally Posted by michael.ngobeni View Post
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).
Last edited by masijade; Jan 7th, 2008 at 7:43 am. Reason: typo, not that its the only one though ;-)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6677 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC