phax / ph-pdf-layout

Java library for creating fluid page layouts with Apache PDFBox. Supporting multi-page tables, different page layouts etc.
Apache License 2.0
64 stars 11 forks source link

Cut Text like "overflow:hidden" in css #34

Closed terrason closed 10 months ago

terrason commented 10 months ago

Hello, I need my table cell hide overflow text, like set "overflow:hidden" style in css Is there any way to do this?

I am now figuring the max words in a cell by:

        // my cell's width is WidthSpec.perc(30)
        double area=0.3*pages.getAvailableWidth() * this.tableCellHeight-(2*Constants.POINTS_PER_MM*Constants.POINTS_PER_MM);
        double areaPerFont=(fontSize + LINE_SPACING*Constants.POINTS_PER_MM)*fontSize;
        this.tableCellWordsLimit=(int)(area / areaPerFont);

Unfortunately this is not work, the result tableCellWordsLimit is higher than seen.

phax commented 10 months ago

Try setting a "maxWidth" and/or "maxHeight" of an object to reproduce this effect. I try to create an example snippet

terrason commented 10 months ago

Try setting a "maxWidth" and/or "maxHeight" of an object to reproduce this effect. I try to create an example snippet

Thank you for repling. setMaxHeight on Table cell seams not working image

phax commented 10 months ago

Yeah - its overflow:visible

phax commented 10 months ago

I found a way to do this and added it into the latest 7.3.1-SNAPSHOT version. The class AbstractPLBox received a method setClipContent (boolean) which you can use to clip content to the display area. This therefore works for PLBox and PLTableCell. See the example code I created that outputs this PDF: issue34.pdf

If that suits your needs, I will build a release.

terrason commented 10 months ago

Yes, this suits my job. Wonderful

phax commented 10 months ago

Part of the 7.3.1 release