// step 1: creation of a document-object
LwgDocument document = new LwgDocument();
try {
// step 2:
PdfWriter writer = PdfWriter.getInstance(document,
new FileOutputStream("Annotations.pdf"));
// step 3:
writer.setPdfVersion(PdfWriter.VERSION_1_5);
document.open();
// step 4:
PdfContentByte cb = writer.getDirectContent();
// page 1
PdfFileSpecification fs = PdfFileSpecification.fileExtern(writer, "cards.mpg");
writer.addAnnotation(PdfAnnotation.createScreen(writer, new LwgRectangle(200f, 700f, 300f, 800f), "cards.mpg",fs,"video/mpeg",true));
PdfAnnotation a = new PdfAnnotation(writer, 200f, 550f, 300f, 650f,
PdfAction.javaScript("app.alert('Hello');\r", writer));
document.add(new Chunk("click to trigger javascript").setAnnotation(a).setLocalDestination("top"));
writer.addAnnotation(a);
writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new LwgRectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt"));
writer.addAnnotation(PdfAnnotation.createText(writer, new LwgRectangle(200f, 400f, 300f, 500f), "Help", "This Help annotation was made with 'createText'", false, "Help"));
writer.addAnnotation(PdfAnnotation.createText(writer, new LwgRectangle(200f, 250f, 300f, 350f), "Help", "This Comment annotation was made with 'createText'", true, "Comment"));
cb.rectangle(200, 700, 100, 100);
cb.rectangle(200, 550, 100, 100);
cb.rectangle(200, 400, 100, 100);
cb.rectangle(200, 250, 100, 100);
cb.stroke();
document.newPage();
// page 2
writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 700f, 300f, 800f), PdfAnnotation.HIGHLIGHT_TOGGLE, PdfAction.javaScript("app.alert('Hello');\r", writer)));
writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 550f, 300f, 650f), PdfAnnotation.HIGHLIGHT_OUTLINE, "top"));
writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 400f, 300f, 500f), PdfAnnotation.HIGHLIGHT_PUSH, 1, new PdfDestination(PdfDestination.FIT)));
writer.addAnnotation(PdfAnnotation.createSquareCircle(writer, new LwgRectangle(200f, 250f, 300f, 350f), "This Comment annotation was made with 'createSquareCircle'", false));
document.newPage();
// page 3
PdfContentByte pcb = new PdfContentByte(writer);
pcb.setColorFill(new Color(0xFF, 0x00, 0x00));
writer.addAnnotation(PdfAnnotation.createFreeText(writer, new LwgRectangle(200f, 700f, 300f, 800f), "This is some free text, blah blah blah", pcb));
writer.addAnnotation(PdfAnnotation.createLine(writer, new LwgRectangle(200f, 550f, 300f, 650f), "this is a line", 200, 550, 300, 650));
writer.addAnnotation(PdfAnnotation.createStamp(writer, new LwgRectangle(200f, 400f, 300f, 500f), "This is a stamp", "Stamp"));
writer.addAnnotation(PdfAnnotation.createPopup(writer, new LwgRectangle(200f, 250f, 300f, 350f), "Hello, I'm a popup!", true));
cb.rectangle(200, 700, 100, 100);
cb.rectangle(200, 550, 100, 100);
cb.rectangle(200, 250, 100, 100);
cb.stroke();