LwgDocument document1 = new LwgDocument(LwgPageSize.A4, 10, 10, 10, 10);
LwgDocument document2 = new LwgDocument(LwgPageSize.A4, 10, 10, 10, 10);
try {
// step 2:
PdfWriter writer1 = PdfWriter.getInstance(document1,
new FileOutputStream("SimpleAnnotations1.pdf"));
PdfWriter writer2 = PdfWriter.getInstance(document2,
new FileOutputStream("SimpleAnnotations2.pdf"));
// step 3:
writer2.setPdfVersion(PdfWriter.VERSION_1_5);
document1.open();
document2.open();
// step 4:
document1.add(new Paragraph("Each square on this page represents an annotation."));
// document1
PdfContentByte cb1 = writer1.getDirectContent();
Annotation a1 = new Annotation(
"authors", "Maybe it's because I wanted to be an author myself that I wrote iText.",
250f, 700f, 350f, 800f);
document1.add(a1);
Annotation a2 = new Annotation(250f, 550f, 350f, 650f,
new URL("http://www.lowagie.com/iText/"));
document1.add(a2);
Annotation a3 = new Annotation(250f, 400f, 350f, 500f,
"http://www.lowagie.com/iText");
document1.add(a3);
LwgImage image = LwgImage.getInstance("iText.gif");
image.setAnnotation(a3);
document1.add(image);
Annotation a4 = new Annotation(
250f, 250f, 350f, 350f, PdfAction.LASTPAGE);
document1.add(a4);
// draw rectangles to show where the annotations were added
cb1.rectangle(250, 700, 100, 100);
cb1.rectangle(250, 550, 100, 100);
cb1.rectangle(250, 400, 100, 100);
cb1.rectangle(250, 250, 100, 100);
cb1.stroke();
// more content
document1.newPage();
for (int i = 0; i < 5; i++) {
document1.add(new Paragraph("blahblahblah"));
}
document1.add(new Annotation("blahblah", "Adding an annotation without specifying coordinates"));
for (int i = 0; i < 3; i++) {
document1.add(new Paragraph("blahblahblah"));
}
document1.newPage();
document1.add(new Chunk("marked chunk").setLocalDestination("mark"));
// document2
document2.add(new Paragraph("Each square on this page represents an annotation."));
PdfContentByte cb2 = writer2.getDirectContent();
Annotation a5 = new Annotation(100f, 700f, 200f, 800f,
"cards.mpg", "video/mpeg", true);
document2.add(a5);
Annotation a6 = new Annotation(100f, 550f, 200f, 650f,
"SimpleAnnotations1.pdf", "mark");