This is a discussion on pdflib - change text color mid-sentence within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm having some problems with a pdf file I'm compiling dynamically with pdflib, and my searches for ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm having some problems with a pdf file I'm compiling dynamically with pdflib, and my searches for answers have come up empty, so I'm hoping someone else out there has faced the same problem and came up with a solution. I want to change the text color of a word mid-sentence when outputting text to a pdf file. I've looked at pdf_show_boxed and pdf_show_xy, but I dont think either would actually work the way I need, and I'm hoping their is an easier way than trying to step through a long string word by word, then changing color to display one word, and then trying to continue while making it all look as though it flows. This, of course, would open up all kinds of issues in terms of line feeds and the like If anyone has any advice or could help in any way, please let me know because this has been frustrating. Thanks in advance, Michael. |
|
|||
|
On Tue, October 17, 2006 9:50 am, j1c@wildit.net.au wrote:
> I want to change the text color of a word mid-sentence when outputting > text to a pdf file. > > I've looked at pdf_show_boxed and pdf_show_xy, but I dont think either > would actually work the way I need, and I'm hoping their is an easier > way > than trying to step through a long string word by word, then changing > color to display one word, and then trying to continue while making it > all > look as though it flows. This, of course, would open up all kinds of > issues in terms of line feeds and the like > > If anyone has any advice or could help in any way, please let me know > because this has been frustrating. After you do pdf_show_boxed() for the one color, do this: $textx = pdf_get_value($pdf, 'textx', 0); $texty = pdf_get_value($pdf, 'texty', 0); Now you know where PDFlib "left off" for the last word of that color. You can begin again at that point with a new color. Rinse. Repeat. It's probably going to be a pain to finish off a line, and then do a large chunk of text after that, but it's totally do-able. Note that pdf_show_boxed returns all the text that didn't "fit" -- so if you do this with boxes that are one line, and just keep doing that line after line, interspersing with the colored text and using the pdf_get_value() above, this is totally do-able, if somewhat tedious. If the colored text is "rare" enough, it might be worth doing something like: 1. text up to next colored text 2. pdf_get_value() 3. colored text 4. pdf_get_value() 5. one_line box size for pdf_show_boxed, returns rest of text 6. GOTO 1. particularly if you have huge texts and need performance to not loop through it one line at a time for ALL of it. On the plus side, pdflib, in my experience, tends to generate VERY small and compact PDF output, so the bandwidth is as cheap as it can be... YMMV -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |
![]() |
| Thread Tools | |
| Display Modes | |
|
|