Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1946522
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 17:46:38

    最近由于项目需要,开始使用iText写PDF文件,从网上搜索到一些信息,但都是零碎的一些,现在稍微整理一下,仅限于写pdf文件部分。 首先创建一个pdfWriter的模板
    /*
     * Created on 2005-7-1
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - - Code Style - Code Templates
     */
    package javax.print.PDF;

    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;

    import com.lowagie.text.Cell;
    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Paragraph;
    import com.lowagie.text.Rectangle;
    import com.lowagie.text.Table;
    import com.lowagie.text.pdf.PdfWriter;

    /**
     * @author jcoder
     *
     * TODO To change the template for this generated type comment go to Window -
     * Preferences - - Code Style - Code Templates
     */
    abstract public class PDFWriter {
        protected Document document = null;
        protected FileOutputStream out = null;
        protected Rectangle pageSize = null;
        protected String filePath = null;
        protected Cell cell = null;
        protected Paragraph header = null;
        protected Paragraph prg = null;
        protected Table table = null;

        public PDFWriter(String filePath) {
            try {
                this.filePath = filePath;
                document = new Document();
                out = new FileOutputStream(filePath);
                PdfWriter.getInstance(document, out);
                document.open();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (DocumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        public void close() {
            try {
                document.close();
                out.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
 

[1]   

【责编:landy】

--------------------next---------------------

阅读(194) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~