Hello,
I'm using PdfGraphics2D derived from a PdfTemplate to do some drawing, like so:
........
// Create the graphics2D object
PdfContentByte cb = writer.getDirectContent();
final PdfTemplate tp = cb.createTemplate(width, height);
final Graphics2D g2 = tp.createGraphics(width, height);
// draw...
..........
I also want to add some hyperlinked text, so I do the following:
..........
// add rendering hint for hyperlink
g2.setRenderingHint(PdfGraphics2D.HyperLinkKey.KEY_INSTANCE, "www.google.com");
g2.drawString ("This is a link", 200, 200);
// turn off rendering hint
...........
And finally,
...........
g2.dispose();
// add the template at a specific position on the page
cb.addTemplate(tp, 20, 20);
document.close();
...........
This works as expected for the most part, except the action box for the
hyperlink is displaced from the text it is supposed to be on. In the drawString
method call in PdfGraphics2D, the numeric values of the coordinates for
positioning of both the text and the action bounding box seem to be fine, but
the PdfAction for the URL is added directly to the underlying document (using
the document and the writer objects) and not to the PdfTemplate object from
which the Graphics2D object was derived. As a test, I created a Graphics object
directly from the PdfContentByte object and it worked fine.
Unfortunately my application needs the flexibility of PdfTemplate positioning,
so I need to be able to add a URL action to it and have it be positioned
relative to the template, not to the actual document. I did take a look at the
PDF 1.4 specification and didn't see anything that indicated adding an Action
relative to a form XObject was not possible. Please correct me if I'm mistaken,
and do let me know if iText supports what I'm looking for.
Thanks a lot!
-Ruchir
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
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/