易截截图软件、单文件、免安装、纯绿色、仅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 调用Web Service的方法

1.使用HttpClient
用到的jar文件:commons-httpclient-3.1.jar
方法:
预先定义好Soap请求数据,可以借助于XMLSpy Professional软件来做这一步生成。
String soapRequestData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instanc ......

java 面试资料(收集)

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

Java:重写equals()和hashCode()

1.
何时需要重写
equals()
当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念)。
2.
设计
equals()
[1]
使用
instanceof
操作符检查“实参是否为正确的类型”。
[2]
对于类中的每一个“关键域”,检查实参中的域与当前对象中对应的域值。
[2.1]
对于非
float
和 ......

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反射机制

Java中提供了Class类,可以通过Class类获取类的定义信息,包括包名、类名、类上的注释(Annotation)、类的修饰符、父类、继承的接口、构造方法、成员变量和成员方法。这些信息分别使用java.lang.annotation.Annotation、 java.lang.reflect.Constructor、java.lang.reflect.Field、java.lang.reflect.Method、java.lang.re ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号