在java中使用iText拆分PDF文件
使用iText来拆分pdf文件相比PDFBOX要复杂一点。以下示例实现了拆分PDF文件为单页文件,并保存为“文件名-n.pdf”的文件:
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfReader;
/**
* PDF文档的工具
*
* @author Howard
*
*/
public class PDFTool {
/**
* 拆分pdf,返回页数
*
* @throws IOException
* @throws DocumentException
* @throws FileFormatException
* @throws FileNotFoundException
*
*/
public int split(String filePath) throws IOException, DocumentException {
PdfReader reader = new PdfReader(filePath);
int pageCnt = reader.getNumberOfPages();
for (int i = 0; i < pageCnt; i++) {
Document document = new Document(reader.getPageSizeWithRotation(i+1));
PdfCopy copy = new PdfCopy(document, new FileOutputStream(filePath
.substring(0, filePath.length() - 4)
+ "-" + (i + 1) + ".pdf"));
document.open();
copy.addPage(copy.getImportedPage(reader, i+1));
document.close();
}
return pageCnt;
}
}
使用的iText处理pdf相比PDFBOX的好处是,目前有些pdf在使用PDFBOX读取时就会报错,但在iText中却不会,具体原因还有待分析。
因为这个错误也尝试过用“PDFClown”,同样也会报错。
相关文档:
2008 年 6 月 24 日
原文地址: http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0806wangys/
本文介绍 IBM FileNet P8 4.0 Platform 提供的 Content Java API。首先对 FileNet P8 Content Engine 和 API 进行概要介绍, 并说明了一些基本概念,随后详细介绍了 FileNet Content Engine提供的基于 EJB ......
用java调用oracle存储过程总结
1、什么是存储过程。存储过程是数据库服务器端的一段程序,它有两种类型。一种类似于SELECT查询,用于检索数据,检索到的数据能够以数据集的形式返回给客户。另一种类似于INSERT或DELETE查询,它不返回数据,只是执行一个动作。有的服务器允许同一个存储过程既可以返回数据又可以执行动作。
......
对List的遍历有三种方式
List<A> list = new ArrayList<A>();
list.add(new A());
list.add(new & ......
产品下载http://www.fastunit.com/download/download.html 格式
大小(bytes)
发布日期 FastUnit 2.9 普及版*
zip
16,707,279 / 15.9M
2010-05-18
点击下载 《FastUnit开发手册》
pdf
1,716,405 / 1.63M
2010-05-13
点击下载 《FastUnit管理手册》
pdf
300,1 ......