Exemplo n.º 1
0
        /// <summary>
        /// Custom cell's content template as a PdfPCell
        /// </summary>
        /// <returns>Content as a PdfPCell</returns>
        public PdfPCell RenderingCell(CellAttributes attributes)
        {
            if (OnPrintAnnotation == null)
            {
                throw new InvalidOperationException("Please set the OnPrintAnnotation formula.");
            }

            var data = OnPrintAnnotation.Invoke(attributes.RowData.TableRowData);

            if (data == null)
            {
                return(new PdfPCell());
            }

            var defaultFont = attributes.BasicProperties.PdfFont.Fonts[0];
            var chunk       = new Chunk(".", defaultFont);

            chunk.SetAnnotation(
                PdfAnnotation.CreateText(
                    attributes.SharedData.PdfWriter,
                    new Rectangle(100, 100),
                    data.Title,
                    data.Text,
                    false,
                    _annotationIcon[data.Icon]));

            return(new PdfPCell(new Phrase(chunk)));
        }
Exemplo n.º 2
0
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                Phrase phrase;
                Chunk  chunk;
                foreach (Movie movie in PojoFactory.GetMovies())
                {
                    phrase = new Phrase(movie.MovieTitle);
                    chunk  = new Chunk("\u00a0");
                    chunk.SetAnnotation(PdfAnnotation.CreateText(
                                            writer, null, movie.MovieTitle,
                                            string.Format(INFO, movie.Year, movie.Duration),
                                            false, "Comment"
                                            ));
                    phrase.Add(chunk);
                    document.Add(phrase);
                    document.Add(PojoToElementFactory.GetDirectorList(movie));
                    document.Add(PojoToElementFactory.GetCountryList(movie));
                }
            }
        }
Exemplo n.º 3
0
        public void AddWrongAnnotation(String src, String dest)
        {
            PdfReader     reader  = new PdfReader(src);
            PdfStamper    stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
            PdfAnnotation comment = PdfAnnotation.CreateText(stamper.Writer,
                                                             new Rectangle(200, 800, 250, 820), "Finally Signed!",
                                                             "Bruno Specimen has finally signed the document", true, "Comment");

            stamper.AddAnnotation(comment, 1);
            stamper.Close();
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        // ---------------------------------------------------------------------------

        /**
         * Manipulates a PDF file src with the file dest as result
         * @param src the original PDF
         */
        public virtual byte[] ManipulatePdf(byte[] src)
        {
            locations = PojoFactory.GetLocations();
            // Create a reader
            PdfReader reader = new PdfReader(src);

            using (MemoryStream ms = new MemoryStream())
            {
                // Create a stamper
                using (PdfStamper stamper = new PdfStamper(reader, ms))
                {
                    // Add the annotations
                    int           page = 1;
                    Rectangle     rect;
                    PdfAnnotation annotation;
                    Movie         movie;
                    foreach (string day in PojoFactory.GetDays())
                    {
                        foreach (Screening screening in PojoFactory.GetScreenings(day))
                        {
                            movie      = screening.movie;
                            rect       = GetPosition(screening);
                            annotation = PdfAnnotation.CreateText(
                                stamper.Writer, rect, movie.MovieTitle,
                                string.Format(INFO, movie.Year, movie.Duration),
                                false, "Help"
                                );
                            annotation.Color = new BaseColor(
                                System.Drawing.ColorTranslator.FromHtml("#" + movie.entry.category.color)
                                );
                            stamper.AddAnnotation(annotation, page);
                        }
                        page++;
                    }
                }
                return(ms.ToArray());
            }
        }