PdfPCell NoWrap=true overflows width of the PdfPTable

c#, itext

Solution

Instead of `NoWrap` on the cell set the `FixedHeight` to the cell's height. This will cause the cell to overflow the content but not show it as you want.

Problem

When I set a PdfPCell's property `NoWrap = true`, if the text inside the cell is wider than the table, it overflows the width of the table. I have a 36f margin, and I set the `table.WidthPercentage = 100f`, and that is working fine. But if I put a long string of text in a cell with `NoWrap = true`, it goes all the way to the very edges of the document. Is there any way to keep the text in the cell from going outside the width of the table? Here is my code: ``` customFont = FontFactory.GetFont(defaultFontName, 22, Font.BOLD); string vehicleName = vehicle.Name; Phrase vName = new Phrase(vehicleName, customFont); vName.Leading = 22f; table = new PdfPTable(1); table.SpacingAfter = 10f; table.WidthPercentage = 100f; cell = new PdfPCell(vName); cell.Border = 1; cell.HorizontalAlignment = 1; cell.NoWrap = true; cell.Padding = 0; table.AddCell(cell); document.Add(table); ``` And when this displays on the document, it looks like this: As you can see, the text is overflowing the border of the cell. I guess I just assumed that if the cell was NoWrap, it would fill up the cell, then stop when it couldn't show any more. Maybe that's not possible. Or any other ideas on how to make a one-line title that can never wrap to more lines?

Original source