易截截图软件、单文件、免安装、纯绿色、仅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中如何使用amcharts


最近公司碰到需要用图表的形式显示一些数据,我就开始到网上查询,查到了jfreechart和amcharts,这两者我都实现过了,jfreechart最后生成图片,但是图片效果不是我想要的,然后又研究amcharts 它的效果确实很好,而且官方网站上还有好些例子可供下载,网址是:www.amcharts.com
(想要完成一个amcharts图形需要swfobjects. ......

java连接sqlserver2005数据库心得体会

sqlserver数据库:java连接sqlserver2005数据库心得体会 
首先得下载驱动程序到微软网站下载Microsoft SQL Server 2005 JDBC Driver 1.2  解压Microsoft SQL Server 2005 jdbc driver1.2.exe 
得到sqljdbc.jar,用得时候直接加到classpath中去. 
 设置SQL Server服务器 
防止出现 
com.mi ......

关于Boolean类型在flex与java中间传递的问题

  最近在开发过程中发现一个问题:Boolean类型的值无法在flex和java间传递,经过一段研究发现,问题出现在Boolean类型的getter和setter方法上。
      按照javabean的规范,小布尔类型的getter是以is做前缀的,但是大布尔类型的getter就成了以get为前缀了(大布尔作为引用类型,已经被视为普通 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号