Hi,

I'm trying to read in an existing PDF and add an action to it, but I
can't seem to figure out how to make the action work.

I've tried adding the action to the over content, or the under content -
but no luck.

I've tried adding an action to an embedded file (the kind of action I
really need) or an action to an URL (just to see if that could work) and
still no luck.

I've even tried upgrading from iText 2.0.8 to 2.1.3 and still no luck.

I don't get any kind of cursor change (like to a hand) and nothing
happens when I click inside the rectangle that I drew to make it easier
to find the action area.

Any help is much appreciated.

Here's my code:


    public void testAction() throws Exception
    {
        // prepare the output document with the cover sheet
        Document pdfDoc = new Document();
        PdfCopy writer = new PdfCopy(pdfDoc, new
FileOutputStream("content/pdf/actionTest_out.pdf"));
        
        pdfDoc.open();
        
        // Set the coversheet in the output document
        PdfReader reader = new PdfReader("content/pdf/coversheet.pdf");
        int pageCount = reader.getNumberOfPages();
        
        for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++)
        {
            PdfImportedPage page = writer.getImportedPage(reader,
pageNumber);
            
            // Add a link on the first page of the coversheet
            if (pageNumber == 1)
            {
                PdfCopy.PageStamp ps = writer.createPageStamp(page);
                PdfContentByte content = ps.getOverContent();
                PdfAction action = new
PdfAction("http://www.lowagie.com";);
                Rectangle rect = new Rectangle(210, 310, 320, 330);

                // Draw a rectangle around the action so we can find it
easier
                rect.setBorderColor(Color.black);
                rect.setBorderWidth(1);
                rect.setBorder(Rectangle.BOX);
                content.rectangle(rect);
                content.setAction(action, rect.getLeft(),
rect.getBottom(), rect.getRight(), rect.getTop());
                ps.alterContents();
            }

            writer.addPage(page);
        }

        pdfDoc.close();
    }

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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

Reply via email to