grep
grep

Reputation: 5623

add description to attachment - PDFBOX

I adding atachment like this:

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 );

everything works! but how to add description? there is no method for this

enter image description here

I've see the source code: code

the get PDStream. and set set the names for example...

Upvotes: 1

Views: 322

Answers (2)

Ariel Carrera
Ariel Carrera

Reputation: 5213

Another possibility (with PDFBox v2) is:

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

Upvotes: 0

grep
grep

Reputation: 5623

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

Upvotes: 1

Related Questions