合成后第一个PDF显示内容完整:
合成后第二个PDF显示内容出现丢失:
合成方法代码:
public static void mergePdfFiles(List<String> files, String savepath,
boolean deleteSrcFile) {
try {
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileOutputStream(savepath));
document.open();
for (int i = 0; i < files.size(); i++) {
PdfReader reader = new PdfReader(files.get(i));
int n = reader.getNumberOfPages();
for (int j = 1; j <= n; j++) {
PdfImportedPage page = copy.getImportedPage(reader, j);
copy.addPage(page);
document.close();
if (deleteSrcFile) {
for (int i = 0; i < files.size(); i++) {
// FileUtil.deleteFile(files.get(i));
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();