How to create a link to launch an external program?

Tags: actionslaunch actionannotationsiText 7

I am using iTextSharp to create PDF files. Can I use iTextSharp to create a link in pdf that will allow me to launch a program?

The users of this file will have no problem trusting this file. It is part of the functionalities they requested to launch a certain program.

Posted on StackOverflow on Feb 24, 2013 by user1019042

You are looking for a Launch action. I'm the author of the book about iText, and I usually don't talk about this functionality because it's considered being a security hazard (which you point out in your comment: the user really has to trust the PDF).

In iText 7 you'd create a launch action like this (the code can be easily converted to C#):

PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
PdfFileSpec spec = PdfFileSpec.createExternalFileSpec(pdfDoc, "test.txt", true);
PdfAction action = PdfAction.createLaunch(spec);
Paragraph p = new Paragraph(new Link("Click to open test.txt", action));
doc.add(p);
doc.close();

As you see, we’ve created a PdfFileSpec instance to add an external resource (any file/program you wish) and add it directly to the PdfAction.

Click this link if you want to see how to answer this question in iText 5.