使用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是否允许,您可以在任何地方使用相同的实例。通过文档来弄清楚什么允许字体操作。
查看更多的例子。
嗨,我不想在单元格粗体中的完整文本。我希望前两行数据以粗体显示,然后保持正常。试着帮我解决这个问题 – 2011-12-29 16:10:05
使用addElement来添加多个元素。我编辑了我的答案 – 2011-12-29 16:40:55