Ejemplo n.º 1
0
 // ---------------------------------------------------------------------------
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4.Rotate()))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         writer.CompressionLevel = 0;
         // step 3
         document.Open();
         // step 4
         PdfContentByte over  = writer.DirectContent;
         PdfContentByte under = writer.DirectContentUnder;
         locations = PojoFactory.GetLocations();
         List <string>    days = PojoFactory.GetDays();
         List <Screening> screenings;
         foreach (string day in days)
         {
             DrawTimeTable(under);
             DrawTimeSlots(over);
             screenings = PojoFactory.GetScreenings(day);
             foreach (Screening screening in screenings)
             {
                 DrawBlock(screening, under, over);
             }
             document.NewPage();
         }
     }
 }
Ejemplo n.º 2
0
// ---------------------------------------------------------------------------

        /**
         * Creates a table with screenings.
         * @param day a film festival day
         * @return a table with screenings
         */
        public PdfPTable GetTable(string day)
        {
            // Create a table with 7 columns
            PdfPTable table = new PdfPTable(new float[] { 2, 1, 2, 5, 1, 3, 2 });

            table.WidthPercentage          = 100f;
            table.DefaultCell.UseAscender  = true;
            table.DefaultCell.UseDescender = true;
            // Add the first header row
            Font f = new Font();

            f.Color = BaseColor.WHITE;
            PdfPCell cell = new PdfPCell(new Phrase(day, f));

            cell.BackgroundColor     = BaseColor.BLACK;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.Colspan             = 7;
            table.AddCell(cell);
            // Add the second header row twice
            table.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
            for (int i = 0; i < 2; i++)
            {
                table.AddCell("Location");
                table.AddCell("Time");
                table.AddCell("Run Length");
                table.AddCell("Title");
                table.AddCell("Year");
                table.AddCell("Directors");
                table.AddCell("Countries");
            }
            table.DefaultCell.BackgroundColor = null;
            // There are three special rows
            table.HeaderRows = 3;
            // One of them is a footer
            table.FooterRows = 1;
            // Now let's loop over the screenings
            List <Screening> screenings = PojoFactory.GetScreenings(day);
            Movie            movie;

            foreach (Screening screening in screenings)
            {
                movie = screening.movie;
                table.AddCell(screening.Location);
                table.AddCell(screening.Time.Substring(0, 5));
                table.AddCell(movie.Duration.ToString() + " '");
                table.AddCell(movie.MovieTitle);
                table.AddCell(movie.Year.ToString());
                cell              = new PdfPCell();
                cell.UseAscender  = true;
                cell.UseDescender = true;
                cell.AddElement(PojoToElementFactory.GetDirectorList(movie));
                table.AddCell(cell);
                cell              = new PdfPCell();
                cell.UseAscender  = true;
                cell.UseDescender = true;
                cell.AddElement(PojoToElementFactory.GetCountryList(movie));
                table.AddCell(cell);
            }
            return(table);
        }
Ejemplo n.º 3
0
        // ---------------------------------------------------------------------------

        /**
         * Creates a table with movie screenings for a specific day
         * @param connection a connection to the database
         * @param day a day
         * @return a table with screenings
         */
        public PdfPTable GetTable(string day)
        {
            PdfPTable table = new PdfPTable(new float[] { 2, 1, 2, 5, 1 });

            table.WidthPercentage             = 100f;
            table.DefaultCell.UseAscender     = true;
            table.DefaultCell.UseDescender    = true;
            table.DefaultCell.BackgroundColor = BaseColor.LIGHT_GRAY;
            for (int i = 0; i < 2; i++)
            {
                table.AddCell("Location");
                table.AddCell("Time");
                table.AddCell("Run Length");
                table.AddCell("Title");
                table.AddCell("Year");
            }
            table.DefaultCell.BackgroundColor = null;
            table.HeaderRows = 2;
            table.FooterRows = 1;
            List <Screening> screenings = PojoFactory.GetScreenings(day);
            Movie            movie;

            foreach (Screening screening in screenings)
            {
                movie = screening.movie;
                table.AddCell(screening.Location);
                table.AddCell(screening.Time.Substring(0, 5));
                table.AddCell(movie.Duration.ToString());
                table.AddCell(movie.MovieTitle);
                table.AddCell(movie.Year.ToString());
            }
            return(table);
        }
Ejemplo n.º 4
0
// ---------------------------------------------------------------------------

        /**
         * Manipulates a PDF file src with the file dest as result
         * @param src the original PDF
         */
        public override 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 annotations for every screening
                    int           page = 1;
                    Rectangle     rect;
                    PdfAnnotation annotation;
                    foreach (string day in PojoFactory.GetDays())
                    {
                        foreach (Screening screening in PojoFactory.GetScreenings(day))
                        {
                            rect       = GetPosition(screening);
                            annotation = PdfAnnotation.CreateLink(
                                stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_INVERT,
                                new PdfAction(string.Format(IMDB, screening.movie.Imdb))
                                );
                            stamper.AddAnnotation(annotation, page);
                        }
                        page++;
                    }
                }
                return(ms.ToArray());
            }
        }
Ejemplo n.º 5
0
        // ---------------------------------------------------------------------------

        /**
         * @param connection
         * @param day
         * @return
         * @throws SQLException
         * @throws DocumentException
         * @throws IOException
         */
        public PdfPTable GetTable(string day)
        {
            PdfPTable table = new PdfPTable(new float[] { 2, 1, 2, 5, 1 });

            table.WidthPercentage                 = 100f;
            table.DefaultCell.Padding             = 3;
            table.DefaultCell.UseAscender         = true;
            table.DefaultCell.UseDescender        = true;
            table.DefaultCell.Colspan             = 5;
            table.DefaultCell.BackgroundColor     = BaseColor.RED;
            table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(day);
            table.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            table.DefaultCell.Colspan             = 1;
            table.DefaultCell.BackgroundColor     = BaseColor.YELLOW;
            for (int i = 0; i < 2; i++)
            {
                table.AddCell("Location");
                table.AddCell("Time");
                table.AddCell("Run Length");
                table.AddCell("Title");
                table.AddCell("Year");
            }
            table.DefaultCell.BackgroundColor = null;
            table.HeaderRows = 3;
            table.FooterRows = 1;
            List <Screening> screenings = PojoFactory.GetScreenings(day);
            Movie            movie;
            PdfPCell         runLength;

            foreach (Screening screening in screenings)
            {
                movie = screening.movie;
                table.AddCell(screening.Location);
                table.AddCell(screening.Time.Substring(0, 5));
                runLength        = new PdfPCell(table.DefaultCell);
                runLength.Phrase = new Phrase(String.Format(
                                                  "{0} '", movie.Duration
                                                  ));
                runLength.CellEvent = new RunLength(movie.Duration);
                if (screening.Press)
                {
                    runLength.CellEvent = press;
                }
                table.AddCell(runLength);
                table.AddCell(movie.MovieTitle);
                table.AddCell(movie.Year.ToString());
            }
            return(table);
        }
Ejemplo n.º 6
0
 // ===========================================================================
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4.Rotate()))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfContentByte over  = writer.DirectContent;
         PdfContentByte under = writer.DirectContentUnder;
         locations = PojoFactory.GetLocations();
         PdfTemplate t_under = under.CreateTemplate(
             PageSize.A4.Height, PageSize.A4.Width
             );
         DrawTimeTable(t_under);
         PdfTemplate t_over = over.CreateTemplate(
             PageSize.A4.Height, PageSize.A4.Width
             );
         DrawTimeSlots(t_over);
         DrawInfo(t_over);
         List <string>    days = PojoFactory.GetDays();
         List <Screening> screenings;
         int d = 1;
         foreach (string day in days)
         {
             over.AddTemplate(t_over, 0, 0);
             under.AddTemplate(t_under, 0, 0);
             DrawDateInfo(day, d++, over);
             screenings = PojoFactory.GetScreenings(day);
             foreach (Screening screening in screenings)
             {
                 DrawBlock(screening, under, over);
                 DrawMovieInfo(screening, over);
             }
             document.NewPage();
         }
     }
 }
Ejemplo n.º 7
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());
            }
        }
Ejemplo n.º 8
0
// ---------------------------------------------------------------------------

        /**
         * Creates a table with all the screenings of a specific day.
         * The table is composed of nested tables.
         * @param day a film festival day
         * @return a table
         */
        public PdfPTable GetTable(string day)
        {
            // Create a table with only one column
            PdfPTable table = new PdfPTable(1);

            table.WidthPercentage = 100f;
            // add the cell with the date
            Font f = new Font();

            f.Color = BaseColor.WHITE;
            PdfPCell cell = new PdfPCell(new Phrase(day, f));

            cell.BackgroundColor     = BaseColor.BLACK;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell);
            // add the movies as nested tables
            List <Screening> screenings = PojoFactory.GetScreenings(day);

            foreach (Screening screening in screenings)
            {
                table.AddCell(GetTable(screening));
            }
            return(table);
        }
Ejemplo n.º 9
0
// ---------------------------------------------------------------------------

        /**
         * Manipulates a PDF file src with the file dest as result
         * @param src the original PDF
         */
        public override 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)) {
                    // Loop over the days and screenings
                    int           page = 1;
                    Rectangle     rect;
                    float         top;
                    PdfAnnotation annotation;
                    Movie         movie;
                    foreach (string day in PojoFactory.GetDays())
                    {
                        foreach (Screening screening in PojoFactory.GetScreenings(day))
                        {
                            rect  = GetPosition(screening);
                            movie = screening.movie;
                            // Annotation for press previews
                            if (screening.Press)
                            {
                                annotation = PdfAnnotation.CreateStamp(
                                    stamper.Writer, rect, "Press only", "NotForPublicRelease"
                                    );
                                annotation.Color = BaseColor.BLACK;
                                annotation.Flags = PdfAnnotation.FLAGS_PRINT;
                            }
                            // Annotation for screenings that are sold out
                            else if (IsSoldOut(screening))
                            {
                                top        = reader.GetPageSizeWithRotation(page).Top;
                                annotation = PdfAnnotation.CreateLine(
                                    stamper.Writer, rect, "SOLD OUT",
                                    top - rect.Top, rect.Right,
                                    top - rect.Bottom, rect.Left
                                    );
                                annotation.Title       = movie.MovieTitle;
                                annotation.Color       = BaseColor.WHITE;
                                annotation.Flags       = PdfAnnotation.FLAGS_PRINT;
                                annotation.BorderStyle = new PdfBorderDictionary(
                                    5, PdfBorderDictionary.STYLE_SOLID
                                    );
                            }
                            // Annotation for screenings with tickets available
                            else
                            {
                                annotation = PdfAnnotation.CreateSquareCircle(
                                    stamper.Writer, rect, "Tickets available", true
                                    );
                                annotation.Title  = movie.MovieTitle;
                                annotation.Color  = BaseColor.BLUE;
                                annotation.Flags  = PdfAnnotation.FLAGS_PRINT;
                                annotation.Border = new PdfBorderArray(
                                    0, 0, 2, new PdfDashPattern()
                                    );
                            }
                            stamper.AddAnnotation(annotation, page);
                        }
                        page++;
                    }
                }
                return(ms.ToArray());
            }
        }