二、示例程序:
Java代码
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
public class TestPdf {
public static void main(String[] args) {
Document doc = null;
try {
doc = new Document();
PdfWriter.getInstance(doc, new FileOutputStream("C:\\itext.pdf"));
doc.open();
doc.addTitle("测试标题");
doc.addAuthor("wangwei");
doc.addCreationDate();
doc.addSubject("测试主题");
doc.add(new Paragraph("Hello World"));
} catch (Exception e) {
e.printStackTrace();
} finally {
doc.close();
}
}
}