2011-12-29 135 views

回答

10

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

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

+0

嗨,我不想在单元格粗体中的完整文本。我希望前两行数据以粗体显示,然后保持正常。试着帮我解决这个问题 – 2011-12-29 16:10:05

+0

使用addElement来添加多个元素。我编辑了我的答案 – 2011-12-29 16:40:55