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

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

use itext create a PDF file

2019-11-17 06:17:39
字體:
來源:轉載
供稿:網友

import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
/*
 * Created on 2004-11-10
 *
 * TODO To change the template for this generated file go to
 * Window - PReferences - Java - Code Style - Code Templates
 */

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class PDFCreate {

 public static void main(String[] args) throws MalformedURLException, IOException {
  PDFCreate pdfCreate = new PDFCreate();
  try {
   pdfCreate.createPDF();
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (DocumentException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 public void createPDF() throws DocumentException, BadElementException, MalformedURLException, IOException
 {
  Document document = new Document(PageSize.A4);
  //document.addTitle("Title");
  //document.addHeader("header","Header");
  
  PdfWriter.getInstance(document, new FileOutputStream("C:/Helloworld.PDF"));
  
  document.open();
  //add a Word
  document.add(new Paragraph("Hello World!您好!hehe!"));
  //add a table
  Table table = new Table(3);
  table.setBorderWidth(1);
  table.setBorderColor(new Color(0, 0, 255));
  table.setPadding(5);
  table.setSpacing(5);
  Cell cell = new Cell("header");
  cell.setHeader(true);
  cell.setColspan(3);
  table.addCell(cell);
  table.endHeaders();
  cell = new Cell("example cell with colspan 1 and rowspan 2");
  cell.setRowspan(2);
  cell.setBorderColor(new Color(255, 0, 0));
  table.addCell(cell);
  table.addCell("1.1");
  table.addCell("2.1");
  table.addCell("1.2");
  table.addCell("2.2");
  table.addCell("cell test1");
  cell = new Cell("big cell");
  cell.setRowspan(2);
  cell.setColspan(2);
  table.addCell(cell);
  table.addCell("cell test2");
  
  document.add(table);


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 体育| 云安县| 刚察县| 全南县| 乌拉特前旗| 民乐县| 鄂温| 漯河市| 会同县| 孝昌县| 陇川县| 甘肃省| 碌曲县| 潼关县| 张家界市| 湟中县| 介休市| 远安县| 二手房| 镇赉县| 荔浦县| 荃湾区| 肇州县| 苍山县| 天柱县| 昭通市| 麟游县| 志丹县| 百色市| 集安市| 原平市| 河间市| 罗城| 浦江县| 靖宇县| 临朐县| 洛宁县| 宕昌县| 长阳| 绿春县| 连城县|