3

I have many one page pdf files and I would like to merge it into one pdf file with mupdf library on android device. Is this possible?

If it is not possible, can you recommend something else that I can use on android?

Note: all pdf files are encrypted and the resulting pdf file must be also encrypted.

4

2 回答 2

2

虽然查看器所基于的 MuPDF 库能够实现这样的壮举,但查看器应用程序目前无法合并 PDF 文件。

我不知道有任何工具可以合并 PDF 文件并在 Android 上运行,尽管我很容易出错。

至于加密,您将不得不解密所有输入文件,并将最终文件加密为单独的操作。因此,除了允许您指定多个输入文件的 UI、它们的组合顺序(实际上,可能还有每个页面的使用顺序)之外,您还需要能够指定解密密码和最终加密方法。相当复杂的用户界面。

于 2012-11-20T08:20:06.960 回答
1

我不知道如何为 MuPDF 执行此操作,但您可以将 Android 上的多个 PDF 文件与最新的Apache PdfBox Release结合起来。(目前还没有最终确定……RC3……)

只需将此依赖项添加到您的 build.gradle 中:

compile 'org.apache.pdfbox:pdfbox:2.0.0-RC3'

在异步任务中执行以下操作:

private File downloadAndCombinePDFs(String urlToPdf1, String urlToPdf2, String urlToPdf3 ) throws IOException {

    PDFMergerUtility ut = new PDFMergerUtility();
    ut.addSource(NetworkUtils.downloadFile(urlToPdf1, 20));
    ut.addSource(NetworkUtils.downloadFile(urlToPdf2, 20));
    ut.addSource(NetworkUtils.downloadFile(urlToPdf3, 20));

    final File file = new File(getContext().getExternalCacheDir(), System.currentTimeMillis() + ".pdf");

    final FileOutputStream fileOutputStream = new FileOutputStream(file);
    try {
        ut.setDestinationStream(fileOutputStream);
        ut.mergeDocuments(MemoryUsageSetting.setupTempFileOnly());

    } finally {
        fileOutputStream.close();
    }
    return file;
}

这里 NetworkUtils.downloadFile() 应该返回一个 InputStream。如果你的 SD 卡上有它们,你可以打开一个 FileInputStream。

我像这样从互联网上下载PDF:

public static InputStream downloadFileThrowing(String url, int timeOutInSeconds) throws IOException {

    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(timeOutInSeconds, TimeUnit.SECONDS);
    client.setReadTimeout(timeOutInSeconds, TimeUnit.SECONDS);

    Request request = new Request.Builder().url(url).build();

    Response response = client.newCall(request).execute();
    if (!response.isSuccessful())
        throw new IOException("Download not successful.response:" + response);
    else
        return response.body().byteStream();
}

要使用 OkHttpClient,请将其添加到您的 build.gradle:

compile 'com.squareup.okhttp:okhttp:2.7.2'

注意: 这不适用于加密文件。要合并加密文件,您应该首先解密所有单个文件,然后再加密合并的 pdf。

于 2016-02-26T12:40:31.043 回答