How to create a link to launch an external program?

Can I use iTextSharp to create a link in pdf that will allow me to launch a program?

6th November 2015
admin-marketing

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 iTextSharp, you'd create a launch action like this:

    Paragraph p = new Paragraph(
      new Chunk( "Click to open test.txt in Notepad.")
      .SetAction(
        new PdfAction(
          "c:/windows/notepad.exe",
          "test.txt", "open",
          Path.Combine(Utility.ResourceText, "")
        )
    ));
    document.Add(p);

Looking at the code, you immediately see a second problem: PDF is supposed to be platform dependent, but we're introducing two dependencies in this code sample:

  1. in this sample we only provide a launch action for a PDF opened on Windows (one could add extra properties for other OSs).

  2. we assume that the executable is present on the path we defined. That can be a huge problem if you want this PDF to work in every environment.

You'll have to talk this through with your customer to see if they can meet these extra requirements: OS and location of the executable.



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