Replace this line: cb.setAction(action, xOrigin, h - yOrigin - height, xOrigin + stringWidth, h - yOrigin);
In awt the y origin is at the top but in pdf is at the bottom. Best Regards, Paulo Soares > -----Original Message----- > From: Alexendr Molochnikov [SMTP:[EMAIL PROTECTED]] > Sent: Thursday, January 16, 2003 20:03 > To: [EMAIL PROTECTED] > Subject: [iText-questions] PdfAction on PdfContentByte > > Hello, > > I am trying to associate a PdfAction with a rectangular area in > PdfContentByte object using setAction() method. I made a small test case > that draws a number of text strings using Graphics2D object created by > PdfContentByte. For easy identification, the activated area is painted > yellow. The problem is that the action does not seem to take hold: even > the mouse cursor fails to turn into the "pointing finger" when flown over > the area. Could someone have a look at the code and tell me where I am > going wrong? > > The code is ready to compile and is listed below. It creates Pears.pdf > file that demonstrates the problem. > > TIA > > Alex Molochnikov > Gestalt Corporation > > > import java.awt.*; > import java.io.FileOutputStream; > import java.io.IOException; > import com.lowagie.text.*; > import com.lowagie.text.pdf.*; > public class ActionTest > { > public static void main(String[] args) > { > int w = 150; > int h = 500; > Document document = new Document(new > com.lowagie.text.Rectangle(300, 500)); > try > { > PdfWriter writer = PdfWriter.getInstance(document, new > FileOutputStream("Pears.pdf")); > document.open(); > DefaultFontMapper mapper = new DefaultFontMapper(); > mapper.insertDirectory("c:\\windows\\fonts"); > PdfContentByte cb = writer.getDirectContent(); > Graphics2D g2 = cb.createGraphics(w, h, mapper); > g2.setColor(Color.black); > java.awt.Font thisFont = new java.awt.Font("Arial", > java.awt.Font.PLAIN, 18); > g2.setFont(thisFont); > String pear = "Pear"; > FontMetrics metrics = g2.getFontMetrics(); > int width = metrics.stringWidth(pear); > /* > ** Create 10 text strings "PearN" > */ > for (int i = 0; i < 10; i++) > { > int y = i * 30; > if (i == 5) > { > /* > ** "Assign" the action to Pear5 > */ > g2.setColor(Color.blue); > PdfAction action = new > PdfAction("c:\\windows\\notepad.exe", null, null, null); > int height = 20; > int xOrigin = (w - width) / 2 - 2; > int yOrigin = (y + 30) - height + 3; > int stringWidth = metrics.stringWidth(pear + " " + i) > + 5; > cb.setAction(action, xOrigin,h - yOrigin - height, > xOrigin + stringWidth, h - yOrigin); > /* > ** Draw the highlighting rectangle around Pear5 > */ > g2.setColor(Color.yellow); > g2.fillRect(xOrigin, yOrigin, stringWidth, height); > g2.setColor(Color.black); > g2.drawRect(xOrigin, yOrigin, stringWidth, height); > } > g2.drawString(pear + " " + i, (w - width) / 2, y + 30); > g2.setColor(Color.black); > } > g2.dispose(); > } > catch(DocumentException de) { System.err.println(de.getMessage()); > } > catch(IOException ioe) { System.err.println(ioe.getMessage()); } > document.close(); > } > } > NHSDM?X'u?-y&Rw^?Z?h?)?^r?.&z?)z(b+bv?jezg)I"?*. > Zry > X?z z?.TD8Z!xkum?i?, > y+?? ??m4o^?$?zb¢{&j)b b?{j-?+-?.?aa?lb,? > y+??b??+-w+^zb ------------------------------------------------------- This SF.NET email is sponsored by: Thawte.com Understand how to protect your customers personal information by implementing SSL on your Apache Web Server. Click here to get our FREE Thawte Apache Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions