I saw too late that the OP went off-list.
This was my answer, accidentally sent to the OP personally.
John Renfrew wrote:
> So I now have
>
> stamper.addAnnotation(PdfAnnotation.createLink(writer, new Rectangle
> (35,60,30,20), PdfAnnotation.HIGHLIGHT_NONE, "mailto:[email protected]"));
>
> or
>
> stamper.addAnnotation(PdfAnnotation.createLink(stamper, new Rectangle
> (35,60,30,20), PdfAnnotation.HIGHLIGHT_NONE, "mailto:[email protected]"));
>
> neither work. But am I getting warmer????
Your first reflex should be to look at the API docs:
http://1t3xt.info/api/com/lowagie/text/pdf/PdfAnnotation.html#createLink%28com.lowagie.text.pdf.PdfWriter,%20com.lowagie.text.Rectangle,%20com.lowagie.text.pdf.PdfName,%20java.lang.String%29
You're using a createLink() method that creates a link to a "named
destination". Is "mailto:[email protected]" a named destination?
No, it isn't! So that's not going to work.
You should use something like this to create the PdfAnnotation:
PdfAnnotation link = PdfAnnotation.createLink(writer,
new Rectangle(35,60,30,20), PdfAnnotation.HIGHLIGHT_NONE,
new PdfAction("mailto:[email protected]"));
There are other ways to do it, but this works.
Furthermore, you're still not telling the stamper on which page
you want to add the annotation. You have something like:
stamper.addAnnotation(link);
But that doesn't even compile!
It should be:
stamper.addAnnotation(link, 1);
In attachment you can find a working example.
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfAction;
import com.lowagie.text.pdf.PdfAnnotation;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;
public class AddLink {
/**
* Creates a PDF file: hello.pdf
* @param args no arguments needed
*/
public static void main(String[] args) throws DocumentException,
IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Document document = new Document();
PdfWriter.getInstance(document, baos);
document.open();
document.add(new Paragraph("Hello World!"));
document.close();
PdfReader reader = new PdfReader(baos.toByteArray());
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream("test.pdf"));
PdfWriter writer = stamper.getWriter();
PdfAnnotation link = PdfAnnotation.createLink(writer,
new Rectangle(35,60,30,20),
PdfAnnotation.HIGHLIGHT_NONE,
new
PdfAction("mailto:[email protected]?subject=stuff"));
stamper.addAnnotation(link, 1);
stamper.close();
}
}
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/