1.文档内容的根本格局设置
示例代码:
package com.yan.exc;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JOptionPane;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
public class Pdf05C {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("C:\005.pdf"));
document.open();
BaseFont font = BaseFont.createFont(BaseFont.TIMES_ROMAN,BaseFont.CP1252,BaseFont.NOT_EMBEDDED);
BaseFont font2 = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252,BaseFont.NOT_EMBEDDED);
BaseFont font3 = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
//BaseFont.createFont(name, encoding, embedded)
Font chinese = new Font(font3,15,Font.NORMAL);
Font content1 = new Font(font2, 12,Font.BOLD);
Font content = new Font(font, 16);
document.add(new Paragraph("This document is created by iText!",content));
document.add(new Paragraph("www.samsung.com", content1));
document.add(new Paragraph("www.samsung.com"));
document.add(new Paragraph("there are some words",FontFactory.getFont(FontFactory.HELVETICA,15,Font.UNDERLINE)));
document.add(new Paragraph("These content will be deperated!",
FontFactory.getFont(FontFactory.COURIER,15,Font.NORMAL|Font.STRIKETHRU)));
document.add(new Paragraph("中文内容也能够正常显示",chinese));
Chunk uk1 = new Chunk("Text Chunk1",FontFactory.getFont(FontFactory.COURIER_BOLD,12,Font.ITALIC));
Chunk uk2 = new Chunk("Text Chunk2",FontFactory.getFont(FontFactory.COURIER_BOLD,15,Font.BOLD));
uk2.setBackground(new Color(30, 50, 120));
document.add(uk1);
document.add(uk2);
JOptionPane.showMessageDialog(null, "文档已创立!");
document.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}package com.yan.exc;
imp