How to create a JavaScript action to open the attachments panel?

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

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");
c.setAction(PdfAction.javaScript(
    "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.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now