You'll need to plug into an event or two (GenericTag is handy) so you'll
know the PDF coordinates of the image (or chunk) after it's been laid
out. You can then create a PdfAnnotation with what I believe is called
a "local destination" for its action.
myChunk.setGenericTag("myLinkTag");
Then you whip up a subclass of PdfPageEventHelper and override
onGenericTag:
onGenericTag
<http://api.itextpdf.com/com/itextpdf/text/pdf/PdfPageEventHelper.html#o
nGenericTag%28com.itextpdf.text.pdf.PdfWriter,%20com.itextpdf.text.Docum
ent,%20com.itextpdf.text.Rectangle,%20java.lang.String%29> (PdfWriter
<http://api.itextpdf.com/com/itextpdf/text/pdf/PdfWriter.html> writer,
Document <http://api.itextpdf.com/com/itextpdf/text/Document.html>
document, Rectangle
<http://api.itextpdf.com/com/itextpdf/text/Rectangle.html> rect, String
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html> text)
Called when a Chunk with a generic tag is written.
And register it with PdfWriter.setPageEvent().
The rect is the bounding box in PDF coordinates (0,0 is the lower left
corner, increasing towards the top right, 1 point is 1/72 of an inch).
So you'll need to scale the rect you want to get it to "look right" over
the image.
PdfDestinations aren't too difficult to figure out, though you'll
probably need to play around with them a bit to get just the right area
in view.
Once you have a destination, you want to create a link annotation:
PdfAnnotation.createLink(writer, annotRect, highlightStyle,
annotPageNum, destination).
And add it: pdfWriter.addAnnotation( PdfAnnotation.createLink(...) );
I'll leave the details as an Excercise For The Reader.
--Mark Storer
Senior Software Engineer
Cardiff.com
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
________________________________
From: Bob Barnes [mailto:[email protected]]
Sent: Friday, September 17, 2010 3:01 PM
To: Post all your questions about iText here
Subject: [iText-questions] Creating links to/from areas of an
image
all,
I've been scouring the examples and the api for a way to
create areas on an image that can serve as both destinations and links
to other pages in the document. I have images with small areas that need
to behave as links to other pages or more precisely to specific text on
other pages if possible. I also need to have the reverse functionality
where the text can act as a link back to the specific area on the image.
I've used Chunk's to create simple text links, but I'm really coming up
empty on how to overlay links onto images. Since there doesn't seem to
be a way to place a Chunk at an absolute x,y coordinate and I need to
tie the 'hit areas" to specific locations of the image, the Chunk
doesn't look to be a solution.
I've been looking at PdfContentByte, PdfDestination &
PdfAction, but to be blunt I'm in way over my head here. This is just a
huge API to try to get a grasp of in a couple of days;-( I've tried the
following as an experiment, but nothing appears at all and I don't see
any evidence that local goto's are active on the page with the image.
PdfContentByte ovrlay=pdfwri.getDirectContent();
for(int idx=0; idx<bubbles.length; idx++) {
float ctrX;
float ctrY;
float locX;
float locY;
int bubnum;
PdfContentByte cntbyt;
bubble=bubbles[idx];
ctrX=bubble.getField("centerX",0.0f);
ctrY=bubble.getField("centerY",0.0f);
bubnum=bubble.getField("bubbleNum",0);
locX=x+(ctrX*w);
locY=y+(ctrY*h);
cntbyt=new PdfContentByte(pdfwri);
cntbyt.setColorFill(Color.BLUE);
cntbyt.setColorStroke(Color.BLUE);
cntbyt.localGoto(LIST+"
"+sectionNumber+"-"+currentFigure+svcgrpdsc+" "+PART+bubnum, locX-5,
locY-5, locX+5, locY+5);
cntbyt.circle(locX,locY,5.0f);
ovrlay.add(cntbyt);
}
Any advice on how to do this gratefully accepted.
Bob
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3138 - Release Date:
09/17/10 05:24:00
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
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/