itextsharp.dll(4.0.8.0)完整示例
2008-05-14 21:54
private void button1_Click(object sender, EventArgs e)
{
//Document:(文档)生成pdf必备的一个对象,生成一个Document示例
Document document = new Document(PageSize.A4, 30, 30, 5, 5);
//为该Document创建一个Writer实例:
PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.Create));
//打开当前Document
document.Open();
//为当前Document添加内容:
document.Add(new Paragraph("Hello World"));
//另起一行。有几种办法建立一个段落,如:
Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.GetFont(FontFactory.HELVETICA, 12));
//所有有些对象将被添加到段落中:
p1.Add("you can add string here\n\t");
p1.Add(new Chunk("you can add chunks \n")); p1.Add(new Phrase("or you can add phrases.\n"));
document.Add(p1); document.Add(p2); document.Add(p3);
//创建了一个内容为“hello World”、红色、斜体、COURIER字体、尺寸20的一个块:
Chunk chunk = new Chunk("Hello world", FontFactory.GetFont(FontFactory.COURIER, 20, iTextSharp.text.Font.COURIER, new iTextSharp.text.Color(255, 0, 0)));
………………