【问题标题】:add description to attachment - PDFBOX为附件添加描述 - PDFBOX
【发布时间】:2013-08-09 12:23:51
【问题描述】:

我这样添加附件:

PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();

//first create the file specification, which holds the embedded file
PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFile( "Test.txt" );
InputStream is = ...;
PDEmbeddedFile ef = new PDEmbeddedFile(doc, is );
//set some of the attributes of the embedded file
ef.setSubtype( "test/plain" );
ef.setSize( data.length );
ef.setCreationDate( new GregorianCalendar() );
fs.setEmbeddedFile( ef );

//now add the entry to the embedded file tree and set in the document.
Map efMap = new HashMap();
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 );

一切正常! 但是如何添加描述?没有办法解决这个问题

我看过源代码: code

获取 PDStream。并设置名称,例如...

【问题讨论】:

    标签: apache adobe pdfbox


    【解决方案1】:
    solution. I just see with PDF Explorer the structure, where it was done, and then:
    
    fs.getCOSDictionary().setString("Desc", "your describtion");
    

    【讨论】:

      【解决方案2】:

      另一种可能性(使用 PDFBox v2)是:

          //first create the file specification, which holds the embedded file
          PDComplexFileSpecification fs = new PDComplexFileSpecification();
          fs.setFile( "Test.txt" );
          fs.setFileDescription( "my description" );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-19
        • 2015-03-19
        • 2021-09-10
        • 1970-01-01
        • 2011-07-18
        • 2011-02-12
        • 1970-01-01
        相关资源
        最近更新 更多