0

swfファイルをpdfドキュメントに添付しようとしています。以下は私のコードです(pdfbox-examplesから抜粋)。ファイルのサイズに基づいてファイルが添付されていることがわかりますが、添付ファイルの有無にかかわらず、pdfドキュメントで表示/検索できません。テキスト コンテンツは正しく表示されます。誰かが私が間違っていることを教えて、問題を解決するのを手伝ってもらえますか?

        doc = new PDDocument();

        PDPage page = new PDPage();
        doc.addPage( page );
        PDFont font = PDType1Font.HELVETICA_BOLD;
        String inputFileName =   "sample.swf";

        InputStream fileInputStream = new FileInputStream(new File(inputFileName));

        PDEmbeddedFile ef = new PDEmbeddedFile(doc, fileInputStream );
        PDPageContentStream contentStream = new PDPageContentStream(doc, page,true,true);
        //embedded files are stored in a named tree
        PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();
        //first create the file specification, which holds the embedded file
        PDComplexFileSpecification fs = new PDComplexFileSpecification();
        fs.setEmbeddedFile(ef);

        //now lets some of the optional parameters
        ef.setSubtype( "swf" );
        ef.setCreationDate( new GregorianCalendar() );

        //now add the entry to the embedded file tree and set in the document.
        Map<String, COSObjectable> efMap = new HashMap<String, COSObjectable>();
        efMap.put("My first attachment", fs );
        efTree.setNames( efMap );
        //attachments are stored as part of the "names" dictionary in the document catalog
        PDDocumentNameDictionary names = new PDDocumentNameDictionary( doc.getDocumentCatalog() );
        names.setEmbeddedFiles( efTree );
        doc.getDocumentCatalog().setNames( names );
4

3 に答える 3

1

同じことに苦労した後、これが既知の問題であることを発見しました。しばらくの間、添付ファイルが機能していなかったと思います。これは、Apacheフォーラムの問題へのリンクです。ここで使用できるハックが提案されています。私はそれを試してみましたが、うまくいきました!

私が見つけた他の回避策は、PDEmbeddedFilesNameTreeNode で setNames を呼び出して制限を削除した後です 醜いハックですが、pdfboxを再コンパイルしなくても機能します

于 2012-09-04T03:52:22.817 に答える
0

PDF 内の添付ファイルを「検索」または表示するために、そのページをめくってそこにある痕跡 (注釈など) を見つけることはできません。

たとえば、Acrobat Reader 9.x では、左側のサイドバーにある [添付ファイルの表示] アイコン (クリップのようなアイコン) をクリックする必要があります。

于 2012-08-20T22:10:37.560 に答える