added new table features: evenColumns, text color, background color#42
added new table features: evenColumns, text color, background color#42ole1986 merged 13 commits intorospdf:masterfrom
Conversation
|
@Manuzza Many PHP Notices I had to use Using option "evenColumn => 1" causes th table to move out of the docuement [columnText] and [columnFill] does not seem to work I have added an example file "examples/table-enhancements.php". |
|
In addition to my previous message I would color the text with the custom callback: The cell filling of course is a good idea |
|
Hi, Code now complies with E_ALL... Most of our tables are left aligned so evenTables had bugs related to non-left aligned tables... :-) Changed the code so that IF the table maxWidth is NOT set, evenColumns will use the full width of the page (between the pageMargin values, of course). Therefore it effectively ignores xPos and xOrientation. If a maxWidth is set, the table will be positioned according to xPos and xOrientation (tables can still go off the screen if a user sets silly parameters - that is on the user). evenColumns is a recent feature addition by me that was probably not quite ready. The cell colors, on the other hand, was done 5 or so years ago, BEFORE the <c:color> tag. I have converted our application to this method BUT maintained this as an extra setting "[colName]Text". This is superior to wrapping the whole sell in a <c:color> tag because as soon as the table cell wraps to the next line the color of the text is lost. <c:color> is fine for short text cells only (see the table examples - two big columns side-by-side with one using a <c:color> tag and the other applying a color to that column). It is possible that evenColumns still has bugs as there are MANY variations to test... |
|
Well done, I am going to check the Regarding the option |
|
We use a wrapper class to build our tables so if you change the [columnName]Text method to <c:color> we can adjust all of our tables in on place. With regards to <c:color> - I have set up table-examples.php so it fails. The text in the middle column is slightly pink so you can see it on the last column (on white). When a colored column follows another colored column it fails. Also note that you need to check that the color persists when the table cell spans multiple pages (which is what the attached sample does). I have left the [columnFill]Text in the code base but commented it out - therefore it is there if we need it back. |
|
Regarding evenColumns... it does work with centred and right tables... If you do NOT give a maxWidth the maxWidth is effectively the space between the margins and so the table spreads out across the available space. Since the table uses everything between the left and right margins the alignment is irrelevant as the table will look the same in all cases. When maxWidth is specified the even spread is across that width. For example, if the column has a maxWidth of 15cm and there are four columns, each column will be 5cm. The table will be positioned left, right or centre as specified... Using evenColumns = 2 with no maxWidth means that is a centred table is narrow enough, it will be centred on the page using the space that it needs and no more. Each column will have its own width. But a table with a lot of content means it spreads out between the margins. Remember, you can still manually specify the with of any of the columns. In the example table you can specify a narrow width for the "No" column and it is guaranteed to use that width, not matter what other settings are. Therefore you can force a column to be narrower or wider, depending on the content that is in them... |
|
Using custom tags in table cells can be a design error and properly makes more sense to use your solution with the [columnName]Text key. But let take a closer look into this first. Also I would prefer to use Also noted that the |
|
I am happy with renaming those params - we use a wrapper class that sits above Cezpdf to manage tables (so building correct arrays is guaranteed). I can update every single table we generate by changing a single function... :-) I saw the other solution for coloring text and thought it looked messy to implement - that is why i left the code there and only commented it out... :-) Os there anything else I need to do on this for now? Do you want me to put the code back and change the variable name? Is Issue #43 in your hands for now? |
|
I have fixed the issue #43 Also noted another issue which is (i think) related to your Heading background is usually set through: Examples located in: examples/tables.php |
|
I know its pretty hard to customize even a single line in Cpdf without affecting other stuff. Just want to let you know I am really happy that you are taking part of this project - Thank you |
|
I have pushed with [columnName]Text restored but renamed to [columnName]Color... The ability to color a column was not being interfered with by the [columnName]Fill - instead I was looking in the wrong damn place for fetching the column color (array path fixed). I could not see an issue with the column headers... The table-enhancements.php now has:
Therefore only the third column is visibly alternately shaded... |
|
Regarding evenColumns = 2: We have always had intermittent problems with tables not rendering properly. We can have dozen of tables in an output and some of those have 8-10 columns in a table that can span 50 or so pages. Every now and again one column in one row that is usually no more that 10 characters can all of a sudden have 50 characters. In the past when the generation crashes (insufficient RAM) the solution is to manually go comment out every table until you find the culprit and mess with it until you get it working again. The evenColumns 2 is a catch-all that stops this from occurring on odd occasions. Using even columns can look ugly but at least the output is still guaranteed to work. We can then manually narrow or widen specific columns to improve the appearance as the need arises... |
|
found the problem in line 1387 when
So I fixed it |
|
@Manuzza are you OK with these changes or do you want to get your evenColumns = 2 implemented. IMO we should not work around the error they way you did but instead we should correct (set minimum colum width ) before your code lines. What do you think? |
|
evenColumns 2 remains a catch all that only kicks in under a narrow range of parameters. If the column logic is improved it will trigger less which is fine but a table width calculation failure stops an entire PDF being generated. Because our tables can be huge and unpredictable I would have it turned on always, but I understand that not everyone would want that. We can also tweak the min width that is used to determine if it should run (was set to 40 units). So yes I would like to put it back if that is ok... |
|
@Manuzza can you provide me with an example where you had issues with the table generation? |
|
I cannot, as the examples contain proprietary client information. What happens as we understand it is this: One of the auto-columns is calculated to be too narrow for a single character. ezTable tries to put content in the cell and of course fails. ezTable therefore adds a page and fails again. It does this in a loop until the PHP time limit is reached OR the available memory limit is reached (whichever comes first). As I said this is for extremely large tables (both width and height). When we get the issue we either edit the longest content to shorten it or manually force widths on the table. Finding WHICH table in a document can be quite time consuming. These errors in production are still on the very old code base and they are quite rare. But when they do happen everything stops and it is a major burden. We generate hundreds (if not thousands) of documents a day. When I tested the new code on one of our longest documents the table error occurred in numerous places (this was before the bug fixes you have put in place). evenColumns was my response to this. |
|
Hi, Yet to test the merged but 2 comments... It may be worth mentioning in the documentation that evenColumns does not touch any columns that have a specified width, so the user still has a measure of control over the layout. Also, the table on page 8 of the manual looks broken somehow... |

New table option: "evenColumns"
default value = 0 (it does nothing)
If evenColumns = 1 then instead of calculating the width based on the size of the content it will spread the columns evenly (each column will be the same width). Note that it will only evenly distribute columns that do NOT have a specified width. For example, columns that have a manually specified width will continue to use that width.
If evenColumns = 2 then it will only evenly balance the columns if the following criteria is met:
This solves the problem that occurs when a column is very narrow and the table generator gets stuck in a loop adding page after page trying to make the content fit.
New cell option for specifying the Text and Background color:
Every single cell in a table can now have its own specific background color AND text color. For any cell in the data array you want to change the colour, simply add the fields [columnName]Fill and [columnName]Text with a color array.
For example if we enhance the example in the manual (additions in bold):
$data = array(
array('num'=>1,'name'=>'gandalf','type'=>'wizard','typeFill'=>array(0,1,0))
,array('num'=>2,'name'=>'bilbo','type'=>'hobbit','typeFill'=>array(0.588235294118, 0.407843137255, 0))
,array('num'=>3,'name'=>'frodo','type'=>'hobbit','typeFill'=>array(0.588235294118, 0.407843137255, 0))
,array('num'=>4,'name'=>'saruman','type'=>'bad dude','typeFill'=>array(1,0,0),'typeText'=>array(1,1,1,))
,array('num'=>5,'name'=>'sauron','type'=>'really bad dude','typeFill'=>array(0,0,0),'typeText'=>array(1,1,1,))
);
The cell containing the word:
"wizard" will have a green background.
"hobbit" will have a brown background.
"bad dude" will have a red background with white text.
"really bad dude" will have a black background with white text.
Background colors of a cell will be selected using the following precedence: