<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 閱讀(1468) 評論(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();

     }

    }


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


    網站導航:
     
    主站蜘蛛池模板: 中文字幕在线免费观看视频| 亚洲第一成年网站视频| 中文字幕第13亚洲另类| 久久精品国产精品亚洲艾| 中文字幕一区二区免费| 性xxxxx免费视频播放| 亚洲第一精品电影网| 未满十八私人高清免费影院| 国产99视频精品免费视频7| 国产综合成人亚洲区| 亚洲XX00视频| 亚洲视频无码高清在线| 黄页网站免费观看| 亚洲精品狼友在线播放| 亚洲AⅤ男人的天堂在线观看 | 美女啪啪网站又黄又免费| 日本特黄a级高清免费大片| 污污视频免费观看网站| 中文字幕在亚洲第一在线| 日本一道本不卡免费| 亚洲六月丁香六月婷婷蜜芽| 国产精品69白浆在线观看免费| 久久精品夜色噜噜亚洲A∨| a国产成人免费视频| 亚洲色偷偷av男人的天堂 | 亚洲精品精华液一区二区| 国产大片线上免费看| A毛片毛片看免费| 中文字幕亚洲综合精品一区| 免费人成在线视频| 免费看又黄又爽又猛的视频软件| 免费精品国偷自产在线在线 | 69视频在线观看高清免费| 亚洲av无码片区一区二区三区| 东方aⅴ免费观看久久av| 精品日韩亚洲AV无码一区二区三区 | 免费视频精品一区二区| 亚洲αv久久久噜噜噜噜噜| 91情侣在线精品国产免费| 一道本在线免费视频| 亚洲欧洲国产视频|