PhilterPaper / PDF-Table

Official repository for PDF::Table in Perl
https://www.catskilltech.com/FreeSW/product/PDF%2DTable/title/PDF%3A%3ATable/freeSW_full
Other
10 stars 15 forks source link

calculate table height in advance #69

Closed davewood closed 1 year ago

davewood commented 3 years ago

is it possible to calculate the height of the table BEFORE adding it to the pdf by executing $pdftable->table(...)?

example: I have 2 tables. if both of them do not fit on the current page i want to create a new page and add the two tables there.

PhilterPaper commented 3 years ago

In #52, I propose to add a flag to return the height of each row and the overall height, to allow you to decide the height parameter desired (controlling where to split the table on each page, via an array of heights and y positions). There's no reason you couldn't use this information to decide whether to start a table on this page or the next, and whether you could fit two tables on one page. Does that sound like something that would satisfy your request?

davewood commented 3 years ago

this one? -> https://github.com/PhilterPaper/PDF-Table/issues/52#issuecomment-733377695

I guess that would work. the array returned contains the height of the table to be inserted but doesnt add anything to the pdf file, right? why is it an array though, what else is returned?

PhilterPaper commented 3 years ago

Its primary purpose is to try to fit a table across multiple pages without splitting within any row, by knowing the height of each row (and the header and [future] footer). The first element (total height) is all you're interested in.

davewood commented 3 years ago

sounds great, any idea when this enhancement canbe expected?

as usual, thank you for the swift and productive feedback.

PhilterPaper commented 3 years ago

What's currently on my plate for PDF::Table:

  1. fix column width problem
  2. possibly implement format control (preserve source spaces)
  3. row heights (the one we're discussing here)

I would guess at this point to see the row heights by late summer, unless some higher priority problem (bug) shows up, in PDF::Table or PDF::Builder. Or, revenue-generating work ramps up. All I can say at this point is that it's on the list, and I will get to it as soon as I can.

PhilterPaper commented 2 years ago

A related item could be using something like Text::Layout formatting to determine the height of a cell, and feeding that in to PDF::Table to specify the row(s) height. That is, externally specify the height of row(s) via min_rh but using that as an absolute height and not a minimum (i.e., don't recalculate the actual vertical space needed; possibly just cut off the cell content if it overflows). In general, a max_rh might be useful to add (min = max = externally calculated height). The same might be done for cell width, too. Consideration should be given to integrating Text::Layout (or similar) into PDF::Builder to hide this extra step from the user.

Update: per #74, it looks like Text::Layout isn't quite there yet (no word wrap).

PhilterPaper commented 2 years ago

Dave, I have implemented this and put it in the library (GitHub). The files of interest are lib/PDF/Table.pm, INFO/Table.html, and examples/vsizes.pl. The new option is ink => 0. Please give it a try and let me know if it meets your needs.

Sorry to take so long, but it's been a tough last year and there was also a bunch of stuff queued up in front of it. Maybe I can get a new PDF::Table release out within the next few months?

PhilterPaper commented 1 year ago

This is in the 1.004 release just sent to CPAN. See examples/vsizes.pl for an example of using.

davewood commented 1 year ago

thank you so much!

I will test it and tell you about my experience!