fpdf2 icon indicating copy to clipboard operation
fpdf2 copied to clipboard

More control over table borders

Open tfenne opened this issue 2 years ago • 5 comments

Please explain your intent The Table feature is fantastic, but I find that I want more control over borders that is provided by TableBorderLayout. I would really like to be able to control exactly which borders are turned on, and ideally also their thickness, independently.

Describe the solution you'd like I was thinking that perhaps:

  1. TableBorderLayout could become a regular class instead of an enum, so that a user could create instances of it
  2. The existing values (e.g. HORIZONTAL_LINES) could still be class variables so that existing usage doesn't break
  3. The class would hold on to a function/lamba that is called for every border segment for a table, and would return perhaps a thickness (0=off?) and a color (so table borders don't have to be black).

For (3) I'm imagining the function looking something like:

def should_render(rownum: int, colnum: int, is_header: bool, is_footer:bool, side: ?) -> ...?

Additional context I'm actually trying to port some nasty Rmarkdown -> latex -> PDF code, and users have gotten used to some latex table styling, which I can't reproduce. One example is a table with i) thick borders above/below the table, ii) thin borders under the headerline, iii) no other borders.

tfenne avatar Oct 13 '23 19:10 tfenne

Another interesting suggestion, @tfenne!

The current border handling for tables is indeed not particularly flexible, since the available combinations of border lines are essentially hardcoded. As another consequence, they will all have the same color (I haven't checked, but I think FPDF.draw_color should take effect here).

Your idea introduces a lot more complexity, but might actually work. As always, the proof is in the PR... :wink:

gmischler avatar Oct 15 '23 11:10 gmischler

Hi @tfenne 😊

Would like to move forward with this suggestion and work on a PR?

Lucas-C avatar Oct 30 '23 14:10 Lucas-C

@Lucas-C: someone else (@tedbrookings) on my team is actually actively working on this and will submit a PR hopefully this week.

tfenne avatar Oct 30 '23 15:10 tfenne

FYI, I just posted an update there: https://github.com/py-pdf/fpdf2/pull/1005#issuecomment-2410516792

I apologize for the delay it took for us to answer you 🙏 Maintaining fpdf2 is 100% volunteer work, but still I think I should have taken the time to answer you earlier.

Lucas-C avatar Oct 14 '24 09:10 Lucas-C

@Lucas-C - I totally understand, and appreciate you circling back now. My teams use of fpdf2 is sporadic, but coincidentally we're just picking up another project where we need to use it, so the timing is actually great.

tfenne avatar Oct 14 '24 12:10 tfenne