向附件添加说明 - PDFBOX

时间:2013-08-09 12:23:52

标签: apache adobe pdfbox

我添加这样的atachment:

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 );
一切正常! 但如何添加说明?这个没有方法

enter image description here

我看到了源代码: code

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

2 个答案:

答案 0 :(得分:1)

solution. I just see with PDF Explorer the structure, where it was done, and then:

fs.getCOSDictionary().setString("Desc", "your describtion");

enter image description here

答案 1 :(得分:0)

另一种可能性(对于PDFBox v2)是:

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