资源简介
通过SQL及JDBC模式导出各类业务数据,以PDF文件格式存放,要求该文件只能查看和打印(不能编辑和篡改),要有公司相关标志和水印功能。
1、生成PDF文件
2、PDF文件注明版权
3、PDF增加文字和图片水印
4、PDF表格列数可能很多,比如1-50列信息,导出时需判断A4纸格式或其他格式宽度。
5、PDF表格行数量可能超大,比如10万以上,甚至100万以上。

代码片段和文件信息
package com.fruitking.testpdf.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.baseFont;
import com.lowagie.text.pdf.PdfWriter;
public class PDFCreate1File {
/**
* 创建一份PDF文档
* @param fullFilePath
*/
public boolean createPDFFile(String fullFilePath){
Document pdfDocument = new Document();
try {
//构建一个PDF文档输出流程
OutputStream pdfFileOutputStream = new FileOutputStream(new File(fullFilePath));
PdfWriter.getInstance(pdfDocumentpdfFileOutputStream);
//设置中文字体和字体样式
baseFont bfChinese = baseFont.createFont(“STSong-Light“ “UniGB-UCS2-H“ baseFont.NOT_embedDED);
Font f2 = new Font(bfChinese 2 Font.NORMAL);
Font f6 = new Font(bfChinese 6 Font.NORMAL);
Font f10 = new Font(bfChinese 10 Font.NORMAL);
Font f12 = new Font(bfChinese 12 Font.BOLD);
//打开PDF文件流
pdfDocument.open();
//设置PDF文件正文内容
pdfDocument.add(new Paragraph(“中国程序员周报“ f12));
//换行
pdfDocument.add(new Paragraph(“ “f6));
//换行
pdfDocument.add(new Paragraph(“中国程序员工作时间调查报告“ f10));
//换行
pdfDocument.add(new Paragraph(“ “ f2));
return true;
}catch(FileNotFoundException de) {
de.printStackTrace();
System.err.println(“pdf file: “ + de.getMessage());
return false;
}catch(DocumentException de) {
de.printStackTrace();
System.err.println(“document: “ + de.getMessage());
return false;
}catch(IOException de) {
de.printStackTrace();
System.err.println(“pdf font: “ + de.getMessage());
return false;
}finally{
//关闭PDF文档流,OutputStream文件输出流也将在PDF文档流关闭方法内部关闭
if(pdfDocument!=null){
pdfDocument.close();
}
}
}
/**
* 创建一份PDF文档,且标注作者等信息
* @param fullFilePath
*/
public boolean createPDFFileWithCreatorInfo(String fullFilePath){
Document pdfDocument = new Document();
try {
//构建一个PDF文档输出流程
OutputStream pdfFileOutputStream = new FileOutputStream(new File(fullFilePath));
PdfWriter pdfWriter = PdfWriter.getInstance(pdfDocumentpdfFileOutputStream);
//PDF版本(默认1.4)
pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_4);
//文档属性
pdfDocument.addtitle(“水果大王信息技术有限公司数据安全产品“);
pdfDocument.addAuthor(“杭州水果大王信息技术有限公司“);
pdfDocument.addSubject(“文件导出的信息安全管控“);
pdfDocument.addKeywords(“文件导出信息安全“);//文档关键字信
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-03-27 10:34 lib\
文件 1825962 2013-10-18 12:10 lib\bcprov-ext-jdk15-1.46.jar
文件 331811 2014-03-27 09:38 lib\iTextAsian.jar
文件 1130070 2014-03-27 09:38 lib\itext-2.1.7.jar
文件 2243307 2013-10-18 10:47 lib\itext-4.2.1.jar
文件 157360 2013-10-18 10:46 lib\itext-rtf-2.1.7.jar
文件 72229 2013-10-18 10:47 lib\itext-rups-2.1.7.jar
文件 13862 2013-10-20 23:53 pfd大量数据的表格及水印.docx
目录 0 2014-03-27 10:25 testpdf\
文件 483 2013-10-18 12:10 testpdf\.classpath
文件 383 2013-10-18 10:19 testpdf\.project
目录 0 2013-10-21 00:00 testpdf\src\
目录 0 2013-10-21 00:00 testpdf\src\com\
目录 0 2013-10-21 00:00 testpdf\src\com\fruitking\
目录 0 2013-10-21 00:00 testpdf\src\com\fruitking\testpdf\
目录 0 2014-03-27 10:25 testpdf\src\com\fruitking\testpdf\util\
文件 14350 2013-10-20 23:09 testpdf\src\com\fruitking\testpdf\util\PDFCreate1File.java
文件 16335 2013-10-20 21:41 testpdf\src\com\fruitking\testpdf\util\PDFCreate2Table.java
文件 29857 2013-10-20 23:31 testpdf\src\com\fruitking\testpdf\util\PDFCreate2WaterMark.java
文件 5697 2013-10-20 23:42 testpdf\src\com\fruitking\testpdf\util\PdfFileExport.java
文件 9656 2013-10-20 23:28 testpdf\src\com\fruitking\testpdf\util\PdfFileExportUtil.java
相关资源
- 微博系统(Java源码,servlet+jsp),适
- java串口通信全套完整代码-导入eclip
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
评论
共有 条评论