java pdf merger合併使用PDFBox
元件download位置:https://pdfbox.apache.org/
import org.apache.pdfbox.multipdf.PDFMergerUtility;
if (fileEntry.getName().indexOf(ymd) > -1) {
combinePdf(sourcePath + "//" + fileEntry.getName(), destPath + "//" + fileEntry.getName() + "//");
}
public static void combinePdf(String sourcePath, String destPath) {
try {
PDFMergerUtility mergePdf = new PDFMergerUtility();
String folder = sourcePath;
File _folder = new File(folder);
File[] filesInFolder;
filesInFolder = _folder.listFiles();
for (File string : filesInFolder) {
log.info("pdf fileName=" + string);
if (!string.isDirectory()) {
mergePdf.addSource(string);
}
}
mergePdf.setDestinationFileName(destPath + ymd + ".pdf");
mergePdf.mergeDocuments();
} catch (Exception e) {
log.warn("pdf merge error!!!" + e.getMessage());
}
}
import org.apache.pdfbox.multipdf.PDFMergerUtility;
if (fileEntry.getName().indexOf(ymd) > -1) {
combinePdf(sourcePath + "//" + fileEntry.getName(), destPath + "//" + fileEntry.getName() + "//");
}
public static void combinePdf(String sourcePath, String destPath) {
try {
PDFMergerUtility mergePdf = new PDFMergerUtility();
String folder = sourcePath;
File _folder = new File(folder);
File[] filesInFolder;
filesInFolder = _folder.listFiles();
for (File string : filesInFolder) {
log.info("pdf fileName=" + string);
if (!string.isDirectory()) {
mergePdf.addSource(string);
}
}
mergePdf.setDestinationFileName(destPath + ymd + ".pdf");
mergePdf.mergeDocuments();
} catch (Exception e) {
log.warn("pdf merge error!!!" + e.getMessage());
}
}
留言
張貼留言