Java/PDF RTF/Goto
Creates 2 documents with links to each other
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 RemoteGotoPDF {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter writerA = PdfWriter.getInstance(document, new FileOutputStream("DocumentA.pdf"));
PdfWriter writerB = PdfWriter.getInstance(document, new FileOutputStream("DocumentB.pdf"));
document.open();
Paragraph pa = new Paragraph(new Chunk("Click this paragraph to go to a certain destination on document B").setRemoteGoto("DocumentB.pdf", "test"));
Paragraph pb = new Paragraph(new Chunk("Click this paragraph to go to a certain destination on document A").setRemoteGoto("DocumentA.pdf", "test"));
// a special remote goto
Paragraph pc = new Paragraph("you can also jump to a ");
pc.add(new Chunk("specific page on another document", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC)).setRemoteGoto("DocumentB.pdf", 1));
document.add(pa);
document.add(pb);
document.add(pc);
document.add(pa);
document.add(pb);
document.add(pc);
document.add(pa);
document.add(pb);
document.add(pc);
}
catch(Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}
Pdf Local Goto
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 LocalGotoPDF {
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("LocalGotoPDF.pdf"));
document.open();
Paragraph p1 = new Paragraph("If you click on ", FontFactory.getFont(FontFactory.HELVETICA,
12));
p1.add(new Chunk("this word", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL,
new Color(0, 0, 255))).setLocalGoto("test"));
p1.add(" you will automatically jump to another location in this document.");
Paragraph p2 = new Paragraph("Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text");
Paragraph p3 = new Paragraph("This paragraph contains a ");
p3.add(new Chunk("local destination", FontFactory.getFont(FontFactory.HELVETICA, 12,
Font.NORMAL, new Color(255, 0, 0))).setLocalDestination("test"));
document.add(p1);
document.add(p2);
document.add(p3);
} catch (Exception e) {
System.err.println(e.getMessage());
}
document.close();
}
}