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);

Recommended Answers

All 8 Replies

Is there a question in there somewhere?

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?"

Do Hello in red, then world in black.

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.

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.

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).

commented: well said :) +1

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"

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.