国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[JAVA100例]039、生成PDF文件

2019-11-18 15:58:29
字體:
來源:轉載
供稿:網友

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.io.*;
import java.util.*;
import java.awt.Color;


/**
 * <p>Title: 生成PDF文件</p>
 * <p>Description: 本實例通過使用iText包生成一個表格的PDF文件</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Filename: myPDF.java</p>
 * @version 1.0
 */
public class myPDF{
/**
 *<br>方法說明:寫PDF文件
 *<br>輸入參數:
 *<br>返回類型:
 */
  public void write(){
   try{
     Document document=new Document(PageSize.A4, 50, 50, 100, 50);
     Rectangle pageRect=document.getPageSize();
     PdfWriter.getInstance(document, new FileOutputStream("tables.pdf"));
     //創建漢字字體
     BaseFont bfsong = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);
     Font fontSong = new Font(bfSong, 10, Font.NORMAL);
     // 增加一個水印
     try {
         Watermark watermark = new Watermark(Image.getInstance("test.jpg"), pageRect.left()+50,pageRect.top()-85);
         watermark.scalePercent(50);
         document.add(watermark);
     }catch(Exception e) {
    System.err.     }
    
      // 為頁增加頁頭信息
     HeaderFooter header = new HeaderFooter(new Phrase("Java實例一百例",fontSong), false);
     header.setBorder(2);
     header.setAlignment(Element.ALIGN_RIGHT);
     document.setHeader(header);
    
   // 為頁增加頁腳信息
     HeaderFooter footer = new HeaderFooter(new Phrase("第 ",fontSong),new Phrase(" 頁",fontSong));
     footer.setAlignment(Element.ALIGN_CENTER);
     footer.setBorder(1);
     document.setFooter(footer);


      // 打開文檔
     document.open();
     //構造表格
     Table table = new Table(4);
     table.setDefaultVerticalAlignment(Element.ALIGN_MIDDLE);
     table.setBorder(Rectangle.NO_BORDER);
     int hws[] = {10, 20, 10, 20,};
     table.setWidths(hws);
     table.setWidth(100);
     //表頭信息
     Cell cellmain = new Cell(new Phrase("用戶信息",new Font(bfSong, 10, Font.BOLD,new Color(0,0,255))));
     cellmain.setHorizontalAlignment(Element.ALIGN_CENTER);
     cellmain.setColspan(4);
     cellmain.setBorder(Rectangle.NO_BORDER);
     cellmain.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
     table.addCell(cellmain);
      //分表頭信息
     Cell cellleft= new Cell(new Phrase("收貨人信息",new Font(bfSong, 10, Font.ITALIC,new Color(0,0,255))));
     cellleft.setColspan(2);
     cellleft.setHorizontalAlignment(Element.ALIGN_CENTER);
     table.addCell(cellleft);
     Cell cellright= new Cell(new Phrase("訂貨人信息",new Font(bfSong, 10, Font.ITALIC,new Color(0,0,255))));
     cellright.setColspan(2);
     cellright.setHorizontalAlignment(Element.ALIGN_CENTER);
     table.addCell(cellright);
    
     //收貨和訂貨人信息,表體內容
     table.addCell(new Phrase("姓名",fontSong));
     table.addCell(new Phrase("張三",fontSong));
     table.addCell(new Phrase("姓名",fontSong));
     table.addCell(new Phrase("李四",fontSong));




發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 缙云县| 虹口区| 宜丰县| 独山县| 双峰县| 大方县| 张家口市| 垣曲县| 阿拉善盟| 新平| 自治县| 峨眉山市| 临潭县| 金阳县| 桃园县| 林周县| 蓬安县| 南投县| 舞钢市| 兴安盟| 青海省| 互助| 余姚市| 清流县| 揭阳市| 苍梧县| 利川市| 石棉县| 丽江市| 永州市| 海门市| 翁牛特旗| 伊吾县| 绥德县| 宁南县| 环江| 开鲁县| 衡阳县| 西昌市| 庆城县| 新闻|