<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請(qǐng)您在轉(zhuǎn)載時(shí)注明出處http://m.tkk7.com/sxyx2008/謝謝合作!!!

    雪山飛鵠

    溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請(qǐng)您在轉(zhuǎn)載時(shí)注明出處http://m.tkk7.com/sxyx2008/謝謝合作!!!

    BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
      215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

    環(huán)境需求:
                    iText-2.1.7.jar
                    iTextAsian.jar
    示例代碼:

    package com.iText.create;

    import java.awt.Color;
    import java.io.File;
    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.Element;
    import com.lowagie.text.Font;
    import com.lowagie.text.HeaderFooter;
    import com.lowagie.text.Image;
    import com.lowagie.text.PageSize;
    import com.lowagie.text.Paragraph;
    import com.lowagie.text.Phrase;
    import com.lowagie.text.Table;
    import com.lowagie.text.pdf.BaseFont;
    import com.lowagie.text.pdf.PdfWriter;

    /**
     * 功能描述:使用Itext組件創(chuàng)建pdf文檔<br>
     * 創(chuàng)建時(shí)間:2010-07-01
     * 
    @author sxyx2008
     *
     
    */

    public class CreatePdf {

        
    public CreatePdf() throws Exception{
            
            
    //創(chuàng)建一個(gè)文檔對(duì)象紙張大小為A4
            Document doc=new Document(PageSize.A4,50,50,50,50);
            
    //設(shè)置要輸出到磁盤上的文件名稱
            PdfWriter writer=PdfWriter.getInstance(doc,new FileOutputStream(new File("徐熙媛.pdf")));
            
    //設(shè)置作者信息
            doc.addAuthor("sxyx2008");
            
    //設(shè)置文檔創(chuàng)建日期
            doc.addCreationDate();
            
    //設(shè)置標(biāo)題
            doc.addTitle("iText測(cè)試");
            
    //設(shè)置值主題
            doc.addSubject("iText");
            
            
    //構(gòu)建頁腳
            HeaderFooter footer=new HeaderFooter(new Phrase(), true);
            
    //設(shè)置頁腳是否有邊框
            
    //0表示無
            
    //1上邊框
            
    //2下邊框
            
    //3上下邊框都有 默認(rèn)都有
            
    //設(shè)置頁腳是否有邊框
            footer.setBorder(0);
            
    //footer.setBorder(1);
            
    //footer.setBorder(2);
            
    //footer.setBorder(3);
            
    //設(shè)置頁腳的對(duì)齊方式
            footer.setAlignment(Element.ALIGN_CENTER);
            
    //將頁腳添加到文檔中
            doc.setFooter(footer);
            
            
    //打開文檔開始寫內(nèi)容
            doc.open();
            
    //Paragraph par1=new Paragraph("Hello,Welcome You");
            
    //Paragraph par2=new Paragraph("你好,中文測(cè)試",ChineseFont());

            
    /*par1.setAlignment(Element.ALIGN_CENTER);
            doc.add(par1);
    */

            
    //par2.setAlignment(Element.ALIGN_CENTER);
            
    //doc.add(par2);
            
            
    //構(gòu)建一段落
            Paragraph par3=new Paragraph("客戶信息表",ChineseFont());
            
    //設(shè)置局中對(duì)齊
            par3.setAlignment(Element.ALIGN_CENTER);
            
    //添加到文檔
            doc.add(par3);
            
            
    //創(chuàng)建一個(gè)四列的表格
            Table table=new Table(4);
            
    //設(shè)置邊框
            table.setBorder(1);
            
            
    //創(chuàng)建表頭
            
            Cell cell1
    =new Cell(new Phrase("編號(hào)",ChineseFont()));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell1.setVerticalAlignment(Element.ALIGN_CENTER);
            cell1.setHeader(
    true);
            cell1.setBackgroundColor(Color.RED);
            
            
            Cell cell2
    =new Cell(new Phrase("姓名",ChineseFont()));
            cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell2.setVerticalAlignment(Element.ALIGN_CENTER);
            cell2.setHeader(
    true);
            cell2.setBackgroundColor(Color.RED);
            
            Cell cell3
    =new Cell(new Phrase("性別",ChineseFont()));
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setVerticalAlignment(Element.ALIGN_CENTER);
            cell3.setHeader(
    true);
            cell3.setBackgroundColor(Color.RED);
            
            Cell cell4
    =new Cell(new Phrase("備注",ChineseFont()));
            cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell4.setVerticalAlignment(Element.ALIGN_CENTER);
            cell4.setHeader(
    true);
            cell4.setBackgroundColor(Color.RED);
            
            
            table.addCell(cell1);
            table.addCell(cell2);
            table.addCell(cell3);
            table.addCell(cell4);
            
    //添加此代碼后每頁都會(huì)顯示表頭
            table.endHeaders();
            
            
            
    //循環(huán)向表格中添加100條記錄 100行4列的表格
            
            
    //以下代碼的作用是創(chuàng)建100行數(shù)據(jù),其中每行有四列,列依次為 編號(hào) 姓名 性別 備注
            for (int i = 1; i <=100; i++{
                
                
    //設(shè)置編號(hào)單元格
                Cell cell11=new Cell(i+"");
                
    //設(shè)置姓名單元格
                Cell cell22=new Cell(new Phrase("徐熙媛",ChineseFont()));
                
    //設(shè)置性別單元格
                Cell cell33=new Cell(new Phrase("",ChineseFont()));
                
    //設(shè)置備注單元格
                Cell cell44=new Cell(new Phrase("好姑娘",ChineseFont()));
                
                
    //單元格水平對(duì)齊方式
                cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
                
    //單元格垂直對(duì)齊方式
                cell11.setVerticalAlignment(Element.ALIGN_CENTER);
                
                cell22.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell22.setVerticalAlignment(Element.ALIGN_CENTER);
                
                cell33.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell33.setVerticalAlignment(Element.ALIGN_CENTER);
                
                cell44.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell44.setVerticalAlignment(Element.ALIGN_CENTER);
                
                
                table.addCell(cell11);
                table.addCell(cell22);
                table.addCell(cell33);
                table.addCell(cell44);
                
            }

            
            
    //將表格添加到新的文檔
            doc.add(table);
            
    //創(chuàng)建新的一頁
            doc.newPage();
            
    //添加圖片
            Image image=Image.getInstance("D:\\Program Files\\myeclipseworkspace\\6.5\\iText\\src\\5.jpg");
            
    //添加到文檔
            doc.add(image);
            
    //設(shè)置對(duì)象方式
            image.setAlignment(Element.ALIGN_CENTER);
            
            doc.close();
            writer.close();
        }

        
        
    //pdf文檔中文字符處理
        public static Font ChineseFont()
        
    {
            BaseFont baseFont
    =null;
            
    try {
                baseFont
    =BaseFont.createFont("STSong-Light","UniGB-UCS2-H"true);
            }
     catch (DocumentException e) {
                e.printStackTrace();
            }
     catch (IOException e) {
                e.printStackTrace();
            }

            Font chineseFont
    =new Font(baseFont,8,Font.NORMAL,Color.BLUE);
            
    return chineseFont;
        }

        
        
        
    public static void main(String[] args) {
            
    try {
                
    new CreatePdf();
            }
     catch (Exception e) {
                e.printStackTrace();
            }

        }


    }

    效果圖:
    posted on 2010-07-01 11:06 雪山飛鵠 閱讀(4014) 評(píng)論(2)  編輯  收藏 所屬分類: javase

    Feedback

    # re: 輕松使用IText組件制作pdf報(bào)表 2010-07-01 13:10 @joe
    太雷人了 你這數(shù)據(jù)。  回復(fù)  更多評(píng)論
      

    # re: 輕松使用IText組件制作pdf報(bào)表 2010-07-01 18:25 雪山飛鵠
    @@joe
    呵呵
    瞎胡鬧了么  回復(fù)  更多評(píng)論
      

    主站蜘蛛池模板: 亚洲一区动漫卡通在线播放| 亚洲男人天堂2020| 自怕偷自怕亚洲精品| 国产高清不卡免费视频| 77777亚洲午夜久久多人| 9久热精品免费观看视频| 国产精品亚洲αv天堂无码| 久99久无码精品视频免费播放| 亚洲午夜爱爱香蕉片| 中文字幕成人免费高清在线| 久久亚洲国产午夜精品理论片| 在线免费播放一级毛片| 亚洲天天做日日做天天欢毛片| 84pao强力永久免费高清| 亚洲自偷自偷精品| 国产免费女女脚奴视频网| 天天爽亚洲中文字幕| 国产成人免费片在线观看 | 毛片免费在线播放| 亚洲AV第一成肉网| 亚洲AV蜜桃永久无码精品| 免费一看一级毛片全播放| 福利免费在线观看| 亚洲网站在线观看| 久久国内免费视频| 黄色三级三级三级免费看| 久久九九亚洲精品| 久久久www成人免费毛片| 国产亚洲欧美在线观看| 亚洲精品国产品国语在线| 亚洲一区免费在线观看| 爱爱帝国亚洲一区二区三区| 国产v亚洲v天堂无码网站| 91精品视频免费| 美女被吸屁股免费网站| 亚洲av无码一区二区乱子伦as| 成年女性特黄午夜视频免费看 | 青青操视频在线免费观看| 亚洲图片激情小说| 亚洲一区二区三区国产精品| 91免费在线播放|