我使用以下代码在iText中显示PDF文件中的一行:
Phrase phraseHeader = new Phrase(18, new Chunk("Registration Form "+registrationForm.getRegistrationDate(), FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)));
Paragraph paragraph=new Paragraph(phraseHeader);
paragraph.setAlignment("center");
document.add(paragraph);
如果我运行此代码,pdf文件将包含以下内容:
Registration Form 26-Apr-2013 11:58:20
我想以较大的字体显示“注册表单”,以较小的字体显示日期/时间,但两者应该在同一行。我怎么能这样做?
答案 0 :(得分:3)
这应该可以解决问题:
Phrase phraseHeader = new Phrase();
phraseHeader.add(
new Chunk("Registration Form ",
FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)));
phraseHeader.add(
new Chunk(registrationForm.getRegistrationDate(),
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
Paragraph paragraph = new Paragraph(phraseHeader);