Exemplo n.º 1
0
        // ---------------------------------------------------------------------------

        /**
         * Adds a popup.
         * @param stamper the PdfStamper to which the annotation needs to be added
         * @param rect the position of the annotation
         * @param title the annotation title
         * @param contents the annotation content
         * @param imdb the IMDB number of the movie used as name of the annotation
         */
        public void AddPopup(PdfStamper stamper, Rectangle rect,
                             String title, String contents, String imdb)
        {
            // Create the text annotation
            PdfAnnotation text = PdfAnnotation.CreateText(
                stamper.Writer,
                rect, title, contents, false, "Comment"
                );

            text.Name  = string.Format("IMDB{0}", imdb);
            text.Flags = PdfAnnotation.FLAGS_READONLY | PdfAnnotation.FLAGS_NOVIEW;
            // Create the popup annotation
            PdfAnnotation popup = PdfAnnotation.CreatePopup(
                stamper.Writer,
                new Rectangle(
                    rect.Left + 10, rect.Bottom + 10,
                    rect.Left + 200, rect.Bottom + 100
                    ),
                null, false
                );

            // Add the text annotation to the popup
            popup.Put(PdfName.PARENT, text.IndirectReference);
            // Declare the popup annotation as popup for the text
            text.Put(PdfName.POPUP, popup.IndirectReference);
            // Add both annotations
            stamper.AddAnnotation(text, 1);
            stamper.AddAnnotation(popup, 1);
            // Create a button field
            PushbuttonField field = new PushbuttonField(
                stamper.Writer, rect,
                string.Format("b{0}", imdb)
                );
            PdfAnnotation widget = field.Field;
            // Show the popup onMouseEnter
            PdfAction enter = PdfAction.JavaScript(
                string.Format(JS1, imdb), stamper.Writer
                );

            widget.SetAdditionalActions(PdfName.E, enter);
            // Hide the popup onMouseExit
            PdfAction exit = PdfAction.JavaScript(
                string.Format(JS2, imdb), stamper.Writer
                );

            widget.SetAdditionalActions(PdfName.X, exit);
            // Add the button annotation
            stamper.AddAnnotation(widget, 1);
        }