import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfCopy;
import com.lowagie.text.pdf.PdfReader;
public static void combinPdf(String[] pdfFilenames, String targetFilename)
throws Exception {
PdfReader reader = null;
Document document = new Document();
PdfCopy pdfCopy = new PdfCopy(document, new FileOutputStream(targetFilename)); //创建一个新文件
int pageCount = 0;
document.open();
for (int i = 0; i < pdfFilenames.length; ++i) {
System.out.println(pdfFilenames[i]);
reader = new PdfReader(pdfFilenames[i]);
pageCount = reader.getNumberOfPages();
for (int j = 1; j <= pageCount; ++j) {
pdfCopy.addPage(pdfCopy.getImportedPage(reader, j));
}
}
document.close();
}
//测试
public static void main(String[] args) throws InterruptedException {
String newFileName = \"D:/新/合成后的新文件.pdf\";//合成后的文件路径
String fillTemplate1 = \"D:1.pdf\";//需要合并的文件路径
String fillTemplate2 = \"D:2.pdf\";
String[] st = {fillTemplate1,fillTemplate2};
try {
combinPdf(st,newFileName);
} catch (Exception e) {
e.printStackTrace();
}
}
继续阅读与本文标签相同的文章
MySQL半同步复制
-
3D打印在玩具行业的应用
2026-05-18栏目: 教程
-
湖北移动誓师第七届世界军人运动会通信保障
2026-05-18栏目: 教程
-
环保新主义:企业无纸化办公
2026-05-18栏目: 教程
-
华能+华为=光伏技术标杆
2026-05-18栏目: 教程
-
淘集集经营模式变更:合伙人自营,主要供应商已成股东合伙人
2026-05-18栏目: 教程
