在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”,同样也会报错。
相关文档:
在成功实现Java调用C++之后,接下来想到能否通过JNA实现Java调用Fortran,今天试验了一下,还是比较容易的。
网上有一个Java调用F95的例子,但是我考虑不仅要实现F95的调用,还要实现F77的调用,所以费了一些周折。
问题的关键在于F77为过程名自动添加了一个尾部的下划线,所以sub1这个过程,到Java一端,就变成了sub1_, ......
1.
何时需要重写
equals()
当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念)。
2.
设计
equals()
[1]
使用
instanceof
操作符检查“实参是否为正确的类型”。
[2]
对于类中的每一个“关键域”,检查实参中的域与当前对象中对应的域值。
[2.1]
对于非
float
和 ......
产品下载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 ......
Java5中提供了新的注释(Annotation),能够为类提供额外信息,本文介绍了如何定义注释、如何使用注释和如何解析注释。
1、定义注释
package ch5;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Ta ......