943,900 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 12602
  • Java RSS
Jan 7th, 2008
0

Change string color

Expand Post »
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);
Reputation Points: 10
Solved Threads: 0
Newbie Poster
michael.ngobeni is offline Offline
20 posts
since Dec 2006
Jan 7th, 2008
0

Re: Change string color

Is there a question in there somewhere?
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 7th, 2008
0

Re: Change string color

Click to Expand / Collapse  Quote originally posted by masijade ...
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?"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
michael.ngobeni is offline Offline
20 posts
since Dec 2006
Jan 7th, 2008
0

Re: Change string color

Do Hello in red, then world in black.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 7th, 2008
0

Re: Change string color

Click to Expand / Collapse  Quote originally posted by masijade ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
michael.ngobeni is offline Offline
20 posts
since Dec 2006
Jan 7th, 2008
0

Re: Change string color

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.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Jan 7th, 2008
1

Re: Change string color

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 8:43 am. Reason: typo, not that its the only one though ;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Sep 3rd, 2010
0
Re: Change string color
One way to do this, will be to embed it in html code. I.e.
String helloStrng = "<html><font color=red> Hello </font></html> World"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
azinyue is offline Offline
1 posts
since Sep 2010
Sep 3rd, 2010
0
Re: Change string color
Click to Expand / Collapse  Quote originally posted by azinyue ...
One way to do this, will be to embed it in html code. I.e.
String helloStrng = "<html><font color=red> Hello </font></html> World"

Not in a PDF document, which this is what this was about.

Closing this two year dead zombie now.

P.S. that is still nothing more than doing hello in red then world in black, which was already suggested.
Last edited by masijade; Sep 3rd, 2010 at 7:30 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: sending mail using javamail api from application.
Next Thread in Java Forum Timeline: String variables' value





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC