使用itext生成pdf并在特定行中加粗

时间:2011-12-29 14:22:31

标签: java itext

您好我能够使用iText生成包含数据的pdf表。如何在特定行中加粗特定数据?

1 个答案:

答案 0 :(得分:14)

首先,您实例化具有所需详细信息的字体对象。在这里,您将指定它是否为Bold。

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是否允许它。浏览文档以找出允许字体操作的内容。

有关更多示例,请参阅此处。

http://www.vogella.de/articles/JavaPDF/article.html