Set Local Destination for chunk : Jump « PDF « Java Tutorial






import java.awt.Color;
import java.io.FileOutputStream;

import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document();

    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    Paragraph p1 = new Paragraph("this is a test");
    p1.add(new Chunk(" another test ", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL,
        new Color(0, 0, 255))).setLocalGoto("jump"));
    p1.add("the lazy dog.");

    Paragraph p2 = new Paragraph("test");
    Paragraph p3 = new Paragraph("test 2");
    p3.add(new Chunk(" has jumped ", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL,
        new Color(0, 255, 0))).setLocalDestination(" cat "));
    p3.add(" dog.");

    document.add(p1);
    document.add(p2);
    document.add(p2);
    document.add(p2);
    document.add(p2);
    document.add(p2);
    document.add(p2);
    document.add(p2);
    document.add(p3);

    document.close();
  }
}








29.63.Jump
29.63.1.Use SimpleNamedDestination
29.63.2.Go to page 2
29.63.3.Remote Goto
29.63.4.Set Local Destination for chunk
29.63.5.Link to a Pdf file
29.63.6.Set up PdfDestination