Java 使用iText生成PDF文件

Java 使用iText生成PDF文件,java,pdf,itext,Java,Pdf,Itext,我使用以下代码使用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);

我使用以下代码使用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

我想用大字体显示“登记表”,用小字体显示日期/时间,但两者应该在同一行。我怎样才能做到这一点呢?

这应该可以做到:

    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);

这应该可以做到:

    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);

@user2007374如果Xavier的代码对您有效,请接受它作为正确答案(使用消息左侧的链接)。@user2007374如果Xavier的代码对您有效,请接受它作为正确答案(使用消息左侧的链接)。