I am wanting to add an external link to an existing page from a pdf. If I understand it correctly, I use the PdfStamper object. In my complete code, I will calculate the X,Y coordinates & the width,height.
Here is my code so far (it does not work)...
import java.io.FileOutputStream;
import java.net.URL;
import com.lowagie.text.Anchor;
import com.lowagie.text.Annotation;
import com.lowagie.text.Document;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
public class Main {
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader("c:\\data\\APlainTest.pdf");
int n = reader.getNumberOfPages();
PdfStamper stamp = new PdfStamper(reader,new FileOutputStream("c:\\data\\itext.pdf"));
int i = 0;
PdfContentByte under;
PdfContentByte over;
while (i < n) {
i++;
//I don't know how to add this to the existing page, so I tried a PdfAction, that still did not work
Annotation a1 = new Annotation(100f,100f,100f,100f,new URL("
http://www.pubpress.com"));
under = stamp.getUnderContent(i);
PdfAction action = new PdfAction(new URL("
http://www.mytestsite.com"));
under.setAction(action,100f,100f,100f,100f);
over = stamp.getOverContent(i);
over.setAction(action,100f,100f,100f,100f);
}
stamp.close();
}
catch (Exception e) {
}
}
}