将两个PDF合并成一个PDF

将两个PDF合并成一个PDF

package com.oncloudsoft.zbznhc.common.util.pdf;

import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.multipdf.PDFMergerUtility;

import java.io.IOException;


public class PdfboxUtil {

    public static void mergePdf(String[] pdfPaths, String mergePdf) throws IOException {

        PDFMergerUtility mergerUtility = new PDFMergerUtility();

        for (String path : pdfPaths) mergerUtility.addSource(path);

        mergerUtility.setDestinationFileName(mergePdf);

        MemoryUsageSetting memUsageSetting = MemoryUsageSetting.setupTempFileOnly();

        mergerUtility.mergeDocuments(memUsageSetting);
    }

    public static void main(String[] args) throws IOException {

        String[] path = {
                "/home/sunyuhua/test/11.pdf",
                "/home/sunyuhua/test/22.pdf"
        };

        String merge = "/home/sunyuhua/test/1+2.pdf";

        mergePdf(path, merge);
    }
}

但是此代码仅能将两个PDF页合并,页面内容不满的时候,无法做到内容合并为一页

你可能感兴趣的:(pdf)