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

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

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

    posts - 41, comments - 15, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    iText生成PDF文件

    Posted on 2014-06-24 16:27 yuhaibo736 閱讀(1463) 評論(0)  編輯  收藏

    import java.awt.Color;
    import java.io.FileOutputStream;

    import com.itextpdf.text.BaseColor;
    import com.itextpdf.text.Document;
    import com.itextpdf.text.Element;
    import com.itextpdf.text.Font;
    import com.itextpdf.text.PageSize;
    import com.itextpdf.text.Phrase;
    import com.itextpdf.text.Rectangle;
    import com.itextpdf.text.pdf.BaseFont;
    import com.itextpdf.text.pdf.PdfPCell;
    import com.itextpdf.text.pdf.PdfPTable;
    import com.itextpdf.text.pdf.PdfWriter;

    public class CellEvents {


     /**
      * @param args
      */
     public static void main(String[] args) {
      Object[] objArr = new Object[]{100,20,300};
      
      Document document = new Document(PageSize.A4.rotate(),50,50,50,50);
      try{
       //bfSongti = BaseFont.createFont("/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
       Font songtiSFivefont = new Font(BaseFont.createFont("/simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED), 9f);//宋體小五號字
             //設置存放位置
             PdfWriter.getInstance(document, new FileOutputStream("D:/test.pdf"));
             document.open();
     
             PdfPTable table = new PdfPTable(5);
       table.setSpacingBefore(10f);
       table.getDefaultCell().setPadding(5);
       //HowbuyBorderPdfPTableEvent event = new HowbuyBorderPdfPTableEvent();
       //table.setTableEvent(event);
       //table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
       table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
       PdfPCell cellTitle = new PdfPCell(new Phrase("總資產\n(萬元)",songtiSFivefont));
       cellTitle.setBorderWidth(2f);
       cellTitle.setBackgroundColor(new BaseColor(new Color(153, 51, 0)));
       cellTitle.setBorderColor(new BaseColor(new Color(153, 51, 0)));
       cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
       cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
       cellTitle.setMinimumHeight(25);
       table.addCell(cellTitle);
     
       cellTitle = new PdfPCell(new Phrase(""));
       cellTitle.setBorder(Rectangle.NO_BORDER);
       cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
       cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cellTitle);
       
       cellTitle = new PdfPCell(new Phrase("當前收益\n(萬元)",songtiSFivefont));
       cellTitle.setBorderWidth(2f);
       cellTitle.setBackgroundColor(new BaseColor(new Color(153, 51, 0)));
       cellTitle.setBorderColor(new BaseColor(new Color(153, 51, 0)));
       cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
       cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cellTitle);
     
       cellTitle = new PdfPCell(new Phrase("",songtiSFivefont));
       cellTitle.setBorder(Rectangle.NO_BORDER);
       cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
       cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cellTitle);
       
       
       cellTitle = new PdfPCell(new Phrase("累計收益\n(萬元)",songtiSFivefont));
       cellTitle.setBorderWidth(2f);
       cellTitle.setBackgroundColor(new BaseColor(new Color(153, 51, 0)));
       cellTitle.setBorderColor(new BaseColor(new Color(153, 51, 0)));
       cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
       cellTitle.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cellTitle);
       
       float[] widths2 = { 24.5f, 12.25f,24.5f,12.25f,24.5f};

       table.setWidths(widths2);
       
       table.setHorizontalAlignment(Element.ALIGN_LEFT);//
       table.setWidthPercentage(70);
       double zzc = objArr[0]==null ? 0:Double.parseDouble(objArr[0].toString());
       double dqsy = objArr[1]==null ? 0:Double.parseDouble(objArr[1].toString());
       double ljsy = objArr[2]==null ? 0:Double.parseDouble(objArr[2].toString());
       PdfPCell cell1 = new PdfPCell(new Phrase(String.valueOf(zzc),songtiSFivefont));
       cell1.setBorderWidth(2f);
       cell1.setBorderColor(new BaseColor(new Color(153, 51, 0)));
       cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
       cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
       cell1.setMinimumHeight(20);
       table.addCell(cell1);
       
       cell1 = new PdfPCell(new Phrase("",songtiSFivefont));
       cell1.setBorder(Rectangle.NO_BORDER);
       cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
       cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cell1);
       
       cell1 = new PdfPCell(new Phrase(String.valueOf(dqsy),songtiSFivefont));
       cell1.setBorderWidth(2f);
       cell1.setBorderColor(new BaseColor(new Color(153, 51, 0)));
       cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
       cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cell1);
       
       cell1 = new PdfPCell(new Phrase("",songtiSFivefont));
       cell1.setBorder(Rectangle.NO_BORDER);
       cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
       cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cell1);
       
       cell1 = new PdfPCell(new Phrase(String.valueOf(ljsy),songtiSFivefont));
       cell1.setBorderWidth(2f);
       cell1.setBorderColor(new BaseColor(new Color(153, 51, 0)));
       cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
       cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
       table.addCell(cell1);
       document.add(table);
      }catch(Exception ex){
       ex.printStackTrace();
      }
            document.close();

     }

    }


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 2022久久国产精品免费热麻豆| 国产无遮挡裸体免费视频在线观看| 91免费播放人人爽人人快乐| 久久亚洲精品成人| 男女一边摸一边做爽的免费视频| 中文字幕亚洲无线码a| 狠狠躁狠狠爱免费视频无码| 国产L精品国产亚洲区久久| caoporn国产精品免费| 亚洲人成中文字幕在线观看| 免费人成黄页在线观看日本| 久久久久亚洲AV无码观看 | 男女交性无遮挡免费视频| 国产一卡二卡≡卡四卡免费乱码| 国产成人久久精品亚洲小说| jjzz亚洲亚洲女人| 两个人日本WWW免费版| 亚洲人成网www| 久久不见久久见免费影院| 亚洲av无码成人影院一区| 国产成人亚洲精品91专区手机| 久久免费高清视频| 亚洲导航深夜福利| 日本久久久免费高清| 一个人看的免费高清视频日本| 亚洲av午夜福利精品一区人妖| 91热成人精品国产免费| 亚洲AV无码专区亚洲AV桃| 亚洲欧洲久久久精品| 99热免费在线观看| 激情无码亚洲一区二区三区| 最新国产AV无码专区亚洲| 国产免费不卡视频| 美女视频黄频a免费| 亚洲图片在线观看| 免费无码又爽又刺激毛片| 91视频免费网站| 国产99在线|亚洲| 久久久久亚洲AV成人网人人网站| 9420免费高清在线视频| 爱情岛论坛亚洲品质自拍视频网站|