Home > Net >  PDFBox - Setting Cover Sheet for PDF Portfolio
PDFBox - Setting Cover Sheet for PDF Portfolio

Time:01-21

I am creating a PDF portfolio from scratch using PDFBox 2.0.16. I create the PDF and add attachments. Once the attachments are added, I then create the PDF Portfolio. The following is the code to create the PDF Portfolio/Package.

COSDictionary collectionDictionary = new COSDictionary();
collectionDictionary.setName( COSName.TYPE, "Collection" );
collectionDictionary.setName( "PDF Filename", "T" );
PDDocumentCatalog catalog = pdfDoc.getDocumentCatalog();
catalog.getCOSObject().setItem( "Collection", collectionDictionary );
pdfDoc.save( pdfFile );

When I open the PDF, the Cover Sheet is a blank page. I would like the Cover Sheet to be the first attachment in the PDF Portfolio/Package so that when a user opens the PDF, the 1st attachment in the portfolio is viewed.

CodePudding user response:

What somewhat worked for me (it positioned to this file, as if I had clicked on it in the list) is this:

collectionDictionary.setString(COSName.D, "Attachment 1");

where "Attachment 1" is the name used in the name tree in this example.

  • Related