我使用Java中的iText生成PDF文件。我的表格列具有固定的宽度和文本,对于单元格中的一行换行而言,这太长了。但是不使用连字符。单词“ Leistungsscheinziffer”显示为:Leistungssc //在此处断裂heinziffer
我使用连字符的代码:
final PdfPTable table = new PdfPTable(sumCols);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.getDefaultCell().setPadding(4f);
table.setWidths(widthsCols);
table.setWidthPercentage(100);
table.setSpacingBefore(0);
table.setSpacingAfter(5);
final Phrase result = new Phrase(text, font);
result.setHyphenation(new HyphenationAuto("de", "DE", 2,2));
final PdfPCell cell = new PdfPCell(table.getDefaultCell());
cell.setPhrase(result);
table.addCell(cell);
...
Run Code Online (Sandbox Code Playgroud)
连字符被激活,以下测试结果为“ Lei-stungs-schein-zif-fer”
Hyphenator h = new Hyphenator("de", "DE", 2, 2);
Hyphenation s = h.hyphenate("Leistungsscheinziffer");
System.out.println(s);
Run Code Online (Sandbox Code Playgroud)
我忘记设置连字符在该表上工作了吗?谢谢你的帮助。如果您需要有关我的代码的更多信息,我会告诉您。