标签:doc str span length merger row int static parent
public static List<File> mergePdf(List<String> filePath) throws Exception { List<File> list = new ArrayList<File>(); long m10 = 10 * 1024 * 1024; long legth = 0; File file = null; PDFMergerUtility mergePdf = new PDFMergerUtility(); for (int i = 0; i < filePath.size(); i++) { file = new File(filePath.get(i)); if (file != null) { if (i == (filePath.size() - 1)) { mergePdf.addSource(file); String mergePdfPath = file.getParentFile() + "\\" + (new Date().getTime()) + ".pdf"; mergePdf.setDestinationFileName(mergePdfPath); mergePdf.mergeDocuments(); list.add(new File(mergePdfPath)); } if (file.length() >= m10) {// 单个文件大于10M,不合并 mergePdf = new PDFMergerUtility(); mergePdf.addSource(file); String mergePdfPath = file.getParentFile() + "\\" + (new Date().getTime()) + ".pdf"; mergePdf.setDestinationFileName(mergePdfPath); mergePdf.mergeDocuments(); list.add(new File(mergePdfPath)); continue; } if ((file.length() + legth) >= m10) {// 合并pdf String mergePdfPath = file.getParentFile() + "\\" + (new Date().getTime()) + ".pdf"; mergePdf.setDestinationFileName(mergePdfPath); mergePdf.mergeDocuments(); list.add(new File(mergePdfPath)); legth = file.length(); mergePdf = new PDFMergerUtility(); mergePdf.addSource(file); } else { legth += file.length(); mergePdf.addSource(file); } } } return list; }
标签:doc str span length merger row int static parent
原文地址:http://www.cnblogs.com/lovedaodao/p/7886455.html