【发布时间】:2011-12-29 14:22:30
【问题描述】:
您好,我可以使用 iText 生成包含数据的 pdf 表格。如何将特定行中的特定数据加粗?
【问题讨论】:
您好,我可以使用 iText 生成包含数据的 pdf 表格。如何将特定行中的特定数据加粗?
【问题讨论】:
首先,您使用所需的详细信息实例化一个字体对象。在这里您将指定它是否为粗体。
Font boldFont = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
Font normalFont = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.ITALIC);
然后在任何你想使用的字体中使用它。
为了添加一个粗体的表格单元格。
PdfPTable table=new PdfPTable(1);
PdfPCell pdfWordCell = new PdfPCell();
Phrase firstLine = new Phrase("text goes here", boldFont );
Phrase secondLine = new Phrase("normal text goes here", normalFont );
pdfWordCell.addElement(firstLine );
pdfWordCell.addElement(secondLine );
table.addCell( pdfWordCell );
创建带有粗体文本的段落的示例。
Paragraph title = new Paragraph("Title of the document", boldFont );
您可以在任何地方使用同一个实例,具体取决于 API 是否允许。浏览文档以找出允许进行字体操作的内容。
更多示例请参见此处。
【讨论】: