简体   繁体   English

使用iText形成PDF文件

[英]PDF file formation using iText

I use the following code to display a line in a PDF file using 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);
paragraph.setAlignment("center");
document.add(paragraph);

If I run this code the pdf file will contain the following: 如果我运行此代码,则pdf文件将包含以下内容:

Registration Form        26-Apr-2013 11:58:20

I want to display the "Registration Form" in a larger font and the date/time in a smaller font, but both should be in the same line. 我想以较大的字体显示“注册表格”,以较小的字体显示日期/时间,但两者应在同一行中。 How can I am do this? 我该怎么办?

This should do the trick: 这应该可以解决问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM