易截截图软件、单文件、免安装、纯绿色、仅160KB

在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 面试资料(收集)

1.简述逻辑操作(&,|,^)与条件操作(&&,||)的区别。(15分)
    a.条件操作只能操作布尔型的,而逻辑操作不仅可以操作布尔型,而且可以操作数值型
    b.逻辑操作不会产生短路
2.下面程序运行会发生什么结果?如果有错误,如何改正? (15分)
interface  A{
  int x = 0; ......

验证日期的Java正则表达式

看火龙果写了一个验证日期的Java正则表达式,就给转了过来
由于使用到了反向预搜索模式“(?<=)”和“(?<!)”,所以这个只能在 Java 中使用,不能在 JavaScript 中使用,JavaScript 不支持反向预搜索。支持 yyyy-MM-dd、yyy-MM-dd、yy-MM-dd 和 y-MM-dd,即年份为 1~4 ......

Ubuntu8.1下安装JDK,配置 Java运行环境

安装完Ubuntu8.1之后,如果想要开发或运行Java程序,就需要安装JDK或JRE。下面就介绍一种最为简便的在Ubuntu中安装JDK
的方法。
众所周知,Sun公司对于Linux下的的JDK安装控制是相当严格:(1)预编译成二进制的JDK包是需要取得Sun公司授权的;(2)Sun公
司有自己的Unix操作系统。或许是因为这两点原因,目前在Linux或U ......

ajax 发送xml文件,java接受xml文件并解析

红色字体为主要代码
jsp页面中
<script language="javascript">
function  updateDB(operate){
  var objDom=new ActiveXObject("msxml.DomDocument");
   var objRoot=objDom.createElement("All");
   objDom.appendChild(objRoot);
  
  var k=document.ge ......

企业级JAVA快速开发

产品下载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 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号