OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

Request for Auto Trim Feature in PdfPCell

Open HemaSudha1498 opened this issue 1 year ago • 2 comments

I propose the addition of an auto trim feature to the PdfPCell class in OpenPDF. Currently, text content exceeding cell width leads to overlap issues with neighboring cells when setNoWrap(true). Kindly Add an option to automatically trim text within a cell to fit its width. This would prevent overflow and improve table layout readability.

If this feature already exists, please let me know how to implement it.

Issue: Screenshot from 2024-03-29 14-59-05

Expected Solution: Screenshot from 2024-03-29 15-13-19

Additionally, could someone assist me in determining the formula for calculating the number of characters that fit within a specified width when the font size is known?

Thank you

HemaSudha1498 avatar Mar 29 '24 09:03 HemaSudha1498

Hi. this would be a nice feature.

asturio avatar Mar 30 '24 07:03 asturio

One possibility would be to set a "trimSize" on the cell or on the column. And if that is set, all cell content could be trimmed by that number of characters. This as a simple solution.

Depending on the used font, you can't determine how many chars fit in a cell, as a 5 char String has different width depending on the content. "iiiii" is much shorter than "VVVVV".

Another approach could be to "cut" the content, and checking the necessary width. And try to find the sweet spot, there the cut will be "perfect".

asturio avatar May 27 '24 15:05 asturio