use itext create a PDF file

雪花飘飞了

雪花飘飞了

2016-02-19 14:30

人生本是一个不断学习的过程,在这个过程中,图老师就是你们的好帮手,下面分享的use itext create a PDF file懂设计的网友们快点来了解吧!

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

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

  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 {

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)

   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);
  

展开更多 50%)
分享

猜你喜欢

use itext create a PDF file

编程语言 网络编程
use itext create a PDF file

user itext create a word file

编程语言 网络编程
user itext create a word file

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

use jscript Create a SQL Server database

Web开发
use jscript Create a SQL Server database

利用iText在JSP中生成PDF报表

Java JAVA基础
利用iText在JSP中生成PDF报表

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Save a File Using a File Save Dialog Box

Web开发
Save a File Using a File Save Dialog Box

Locate a File Using a File Open Dialog Box

Web开发
Locate a File Using a File Open Dialog Box

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

升级win10后没声音怎么办

升级win10后没声音怎么办

取得一个透明颜色

取得一个透明颜色
下拉加载更多内容 ↓