博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
滴水穿石--Java 生成PDF文件--iText使用之入门
阅读量:4697 次
发布时间:2019-06-09

本文共 902 字,大约阅读时间需要 3 分钟。

iText是开源站点sourceforge的一个项目,是用于生成PDF文档的一个Java类库。支持文本,表格,图形的操作,可以方便的跟 Servlet 进行结合。

使用方法:

1、从官网上下载iText.jar,将其构建到自己的项目中,即安装成功。下载地址:

2、参照文档可以开始自己的测试代码了。

最简单的分成如下五个步骤:

step1--创建一个Document

step2--得到一个pdfWriter实例

step3--打开创建的Document

step4--添加内容

step5--关闭文档

下面,开始HelloWorld吧:

import java.io.FileOutputStream;import com.itextpdf.text.Document;import com.itextpdf.text.Paragraph;import com.itextpdf.text.pdf.PdfWriter;public class TestPdf {     public static void main(String[] args) throws Exception{        //step1          Document document = new Document();          //step2          PdfWriter.getInstance(document, new FileOutputStream("first.pdf"));        //step3          document.open();          //step4          document.add(new Paragraph("Hello World,this is my first pdf!"));          //step5          document.close();   }}    }}

转载于:https://www.cnblogs.com/nexiyi/archive/2012/12/07/2808162.html

你可能感兴趣的文章
UIAlertView
查看>>
通过Instant Client包来使用SQL*PLUS
查看>>
ArcGIS:ArcToolBox工具使用——提取DEM/DSM中的高程点
查看>>
Dwarf Tower
查看>>
pat 1074. 宇宙无敌加法器(20)
查看>>
2.Linux环境下配置Solr4.10.3
查看>>
sqlServer 获取最新的一条数据
查看>>
day29
查看>>
Java Web ServletResponse
查看>>
HTML静态网页--JavaScript-语法
查看>>
es 的crud
查看>>
视频采集以及播放的流程
查看>>
mapreduce排序比较器的选取
查看>>
“饮水机”:形象比喻 深入浅出理解RAID
查看>>
Oracle 安装报错 [INS-06101] IP address of localhost could not be determined 解决方法[转]
查看>>
ASP.NET MVC RedirectToRoute类[转]
查看>>
编码理解
查看>>
Flask之flask-script
查看>>
Linux下设置python脚本文件为服务
查看>>
2019.1.5 DOM
查看>>