5

有谁知道一种方法来检测给定的 PDF 文件是 PDF 包还是 PDF 包,而不是“常规”PDF?我更喜欢 Java 解决方案,虽然由于我还没有找到任何关于检测特定类型 PDF 的信息,但我会尽我所能,然后他们会尝试找出 Java 解决方案。

(在搜索过去的问题时,似乎有很多人不知道存在诸如 PDF Portfolios 和 PDF Packages 之类的东西。通常,它们都是 Adob​​e 允许将多个离散的 PDF 打包成单个 PDF 文件的两种方式. 在阅读器中打开 PDF 包会向用户显示嵌入的 PDF 列表,并允许从那里进一步查看。PDF 包似乎有点复杂——它们还包括用于嵌入文件的基于 Flash 的浏览器,然后允许用户从那里提取离散的 PDF。我对它们的问题,以及我希望能够在代码中检测它们的原因是因为 OS X 的内置 Preview.app 无法读取这些文件——所以我我想至少警告我的网络应用程序的用户,上传它们会导致跨平台的兼容性降低。)

4

2 回答 2

0

这个问题很老,但如果有人想知道,这是可能的。可以使用以下命令使用 Acrobat 和 JavaScript 来完成。

 if (Doc.collection() != null)
 {
     //It Is Portfolio
 }

Acrobat JavaScript API 说,“从 Doc.collection 属性中获取一个集合对象。当没有 PDF 集合(也称为 PDF 包和 PDF 组合)时,Doc.collection 返回空值。集合对象用于设置初始集合中的文档,设置集合的初始视图,以及获取、添加和删除集合字段(或类别)。”

于 2012-05-29T15:41:10.743 回答
0
I'm also facing same problem while extracting data through kofax,  but i got solution and its working fine need to add extra jar for Document class.

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class PDFPortfolio {

    /**
     * @param args
     */
    public static void main(String[] args) {

        com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("e:/pqr1.pdf");
        // get collection of embedded files
        com.aspose.pdf.EmbeddedFileCollection embeddedFiles = pdfDocument.getEmbeddedFiles();
        // iterate through individual file of Portfolio
        for(int counter=1; counter<=pdfDocument.getEmbeddedFiles().size();counter++)
        {
            com.aspose.pdf.FileSpecification fileSpecification = embeddedFiles.get_Item(counter);
            try {
                InputStream input = fileSpecification.getContents();
                File file = new File(fileSpecification.getName());
                // create path for file from pdf
              //  file.getParentFile().mkdirs();
                // create and extract file from pdf
                java.io.FileOutputStream output = new java.io.FileOutputStream("e:/"+fileSpecification.getName(), true);
                byte[] buffer = new byte[4096];
                int n = 0;
                while (-1 != (n = input.read(buffer)))
                output.write(buffer, 0, n);

                // close InputStream object
                input.close();
                output.close();
                } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
于 2014-01-29T10:40:06.647 回答