py-pdf/fpdf2

Feature Request: Using fill with multiple columns (bg and borders for paragraphs)

kmauric opened this issue · 4 comments

Hello everyone,

I'm currently working on creating a 3-column layout, and I've found the text_columns feature to be incredibly useful. However, I'm encountering an issue when trying to add fill color to specific headings.

It appears that I can't use the .set_fill_color method alongside .write. Am I overlooking something here?

If anyone has insight on how to incorporate fill color within text columns, I would greatly appreciate your assistance. Thank you in advance for your help!

I'm sure you've noticed that text_columns() doesn't currently support borders and background styling for the columns as a whole.

But what you really seem to want is to set background styling to individual chunks of text within a column. With the traditional methods, this was easy, because each formatted chunk of text requires its own [multi_]cell, which is inherently also a box that can have a background and border. Within text regions such as columns, any part of the text can be formatted differently than the rest, anywhere in the text flow. This makes it tricky to come up with rules about where its background starts and/or ends, because its outline is not necessarily a box. So on the level of individual write() calls, there is no obvious solution.

However, for someting like a heading, which tends to occupy a line (or several) of its own, the paragraph feature could be used. This is not an immediate solution either, but it has recently turned out that paragraphs could generally use some more formatting options than they currently offer (eg. indents, or maybe even specialized paragraph types for things like list items and possibly headings). It might similarly make sense to add a background colour to paragraphs (not quite sure yet about borders, though).

So this is the most likely approach of how your problem might eventually get solved. For now, we'll have to list it as a feature request here. If you (or anyone) want to try to implement it, that would be very welcome. Feel free to ask about any details on how to best integrate it into the existing structure.

Thanks for the response @gmischler . I understand that styling individual text chunks within columns presents challenges. I appreciate the suggestion to utilize the paragraph feature for headings and the potential for expanding paragraph formatting options in the future. Looking forward to any updates on this feature request.

@gmischler: should we keep this issue open as a remainder to implement paragraph styling?
Or that does not really need a reminder and we can close this?

@gmischler: should we keep this issue open as a remainder to implement paragraph styling?

Well, it's a feature request, so it makes sense to keep it in the list until it gets implemented.