OpenApplicationPDF.java Source code

Java tutorial

Introduction

Here is the source code for OpenApplicationPDF.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfWriter;

public class OpenApplicationPDF {
    public static void main(String[] args) {
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("OpenApplicationPDF.pdf"));
            document.open();
            String application = "notepad.exe";
            Paragraph p = new Paragraph(new Chunk("Click to open " + application)
                    .setAction(new PdfAction(application, null, null, null)));
            document.add(p);
        } catch (Exception de) {
            de.printStackTrace();
        }
        document.close();

    }
}