2.2 添加块(Chunk)、短句(Phrase)、段落(Paragraph)和列表(List)对象
Chunk:一个字符串、一个字体、一些属性
两行之间的空间:引导(Leading)
setInitialLeading(16);
setTextRise()--设置上升高度

import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.Font.FontFamily;
import com.itextpdf.text.pdf.PdfWriter;
/**
* Writes a list of countries to a PDF file.
*/
public class CountryChunks {
/** The resulting PDF file. */
public static final String RESULT
= "D:/data/iText/inAction/chapter02/country_chunks.pdf";
/**
* Main method.
*
* @param args no arguments needed
* @throws DocumentException
* @throws IOException
* @throws SQLException
*/
public static void main(String[] args)
throws IOException, DocumentException, SQLException {
new CountryChunks().createPdf(RESULT);
}
/**
* Creates a PDF document.
* @param filename the path to the new PDF document
* @throws DocumentException
* @throws IOException
* @throws SQLException
*/
public void createPdf(String filename)
throws IOException, DocumentException, SQLException{
// step 1
Document document = new Document();
// step 2
PdfWriter.getInstance(document, new FileOutputStream(filename))
.setInitialLeading(16);
// step 3
document.open();
// step 4
document.add(new Chunk("Argentina "));
Font font = new Font(FontFamily

文章详细介绍了使用iTextPDF库在Java中创建PDF文档的过程,包括添加Chunk、Phrase、Paragraph和List对象,以及设置字体、颜色、间距和链接等格式。

被折叠的 条评论
为什么被折叠?



