java - 单元格的文本不呈现并警告“元素不适合当前区域”
问题描述
我正在使用 iText 7.2.0(Java 8,Windows Server 2016)制作表格。
表格不需要溢出(比页面宽),但如果需要,可以在单词中间打破单元格事件。
某些单元格的文本未呈现,我收到此警告:
[main] 警告 com.itextpdf.layout.renderer.RootRenderer - 元素不适合当前区域。
如果我稍微更改一下文本(例如将“i”替换为“I”),它就会起作用。
我该如何解决?这是我的代码或 iText 中的错误吗?
import java.io.FileNotFoundException;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.Style;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.element.Text;
import com.itextpdf.layout.properties.UnitValue;
public class Main {
private static void makeCell(Table table, Style style, String text) {
Cell c = new Cell();
Paragraph p = new Paragraph();
Text t = new Text(text);
c.addStyle(style);
p.add(t);
c.add(p);
table.addCell(c);
}
public static void main(String[] args) throws FileNotFoundException {
PdfWriter writer = new PdfWriter("C:\\Temp\\test.pdf");
PdfDocument pdf = new PdfDocument(writer);
try (Document document = new Document(pdf)) {
Style style = new Style().setBold();
Table table = new Table(UnitValue.createPercentArray(9));
table.useAllAvailableWidth();
table.setFixedLayout();
makeCell(table, style, "Description");
makeCell(table, style, "DescrIption"); /* Capital I */
makeCell(table, style, "Description");
makeCell(table, style, "Description");
makeCell(table, style, "Description");
makeCell(table, style, "DescrIption"); /* Capital I */
makeCell(table, style, "Description");
makeCell(table, style, "Description");
makeCell(table, style, "Description");
document.add(table);
}
}
}
结果- 带有“描述”的单元格不渲染,带有“描述”的单元格渲染。
解决方案
推荐阅读
- amazon-lex - 将解析的意图和槽从 Amazon-Lex 发送回客户端
- visual-studio - Xamarin 表单与 Visual Studio 2017
- java - 中断等待过程android
- android - 日历提醒不适用于 OnePlus 设备
- javascript - AngularJs ng-repeat 跟踪 $index 问题与 angular-bootstrap-switch
- php - cURL PHP 标头和数据
- json - 核心数据 - NSManagedObject(有关系)到 JSON
- asp.net-mvc - MVC 文件上传 - 将路径和文件名保存回数据库
- angular - 如何在 JqxGrid 的单元格渲染器中使用 Angular 管道
- javascript - 从 React Context API 渲染函数中的地图函数渲染 HTML