Legacy notice!

iText 5 is the previous major version of iText's leading PDF SDK. iText 5 has been EOL, and is no longer developed. Switch your project to iText 7, integrating the latest developments.
Check related iText 7 content!

Is there an action which opens the attachments panel? Not right away, but when the user presses some text?

I know the writer.setViewerPreferences(PdfWriter.PageModeUseAttachments) but I don't want it to open right away.

Posted on StackOverflow on Sep 12, 2012 by Michael A

This can be done using a JavaScript action:

Chunk c = new Chunk("Show / Hide attachment panel");
    "app.execMenuItem('ShowHideFileAttachment');", writer));
document.add(new Paragraph(c));

Note that this won't work on all viewers (app = Adobe Reader) and it won't work if people disable Javascript.