Example #1
0
        // ---------------------------------------------------------------------------

        /**
         * Creates a Phrase containing information about a movie.
         * @param    movie    the movie for which you want to create a Paragraph
         */
        public Phrase CreateMovieInformation(Movie movie)
        {
            Phrase p = new Phrase();

            p.Font = FilmFonts.NORMAL;
            p.Add(new Phrase("Title: ", FilmFonts.BOLDITALIC));
            p.Add(PojoToElementFactory.GetMovieTitlePhrase(movie));
            p.Add(" ");
            if (!string.IsNullOrEmpty(movie.OriginalTitle))
            {
                p.Add(new Phrase("Original title: ", FilmFonts.BOLDITALIC));
                p.Add(PojoToElementFactory.GetOriginalTitlePhrase(movie));
                p.Add(" ");
            }
            p.Add(new Phrase("Country: ", FilmFonts.BOLDITALIC));
            foreach (Country country in movie.Countries)
            {
                p.Add(PojoToElementFactory.GetCountryPhrase(country));
                p.Add(" ");
            }
            p.Add(new Phrase("Director: ", FilmFonts.BOLDITALIC));
            foreach (Director director in movie.Directors)
            {
                p.Add(PojoToElementFactory.GetDirectorPhrase(director));
                p.Add(" ");
            }
            p.Add(new Chunk("Year: ", FilmFonts.BOLDITALIC));
            p.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
            p.Add(new Chunk(" Duration: ", FilmFonts.BOLDITALIC));
            p.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
            p.Add(new Chunk(" minutes", FilmFonts.NORMAL));
            p.Add(new LineSeparator(0.3f, 100, null, Element.ALIGN_CENTER, -2));
            return(p);
        }
Example #2
0
// ---------------------------------------------------------------------------

        /**
         * Creates a Paragraph containing information about a movie.
         * @param    movie    the movie for which you want to create a Paragraph
         */
        public Paragraph CreateMovieInformation(Movie movie)
        {
            Paragraph p = new Paragraph();

            p.Font = FilmFonts.NORMAL;
            p.Add(new Phrase("Title: ", FilmFonts.BOLDITALIC));
            p.Add(PojoToElementFactory.GetMovieTitlePhrase(movie));
            p.Add(" ");
            if (!string.IsNullOrEmpty(movie.OriginalTitle))
            {
                p.Add(new Phrase("Original title: ", FilmFonts.BOLDITALIC));
                p.Add(PojoToElementFactory.GetOriginalTitlePhrase(movie));
                p.Add(" ");
            }
            p.Add(new Phrase("Country: ", FilmFonts.BOLDITALIC));
            foreach (Country country in movie.Countries)
            {
                p.Add(PojoToElementFactory.GetCountryPhrase(country));
                p.Add(" ");
            }
            p.Add(new Phrase("Director: ", FilmFonts.BOLDITALIC));
            foreach (Director director in movie.Directors)
            {
                p.Add(PojoToElementFactory.GetDirectorPhrase(director));
                p.Add(" ");
            }
            p.Add(CreateYearAndDuration(movie));
            return(p);
        }
Example #3
0
 // ===========================================================================
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         document.Add(new Paragraph("Movies:"));
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             PdfPTable table = new PdfPTable(2);
             table.SetWidths(new int[] { 1, 4 });
             PdfPCell cell;
             cell = new PdfPCell(new Phrase(movie.Title, FilmFonts.BOLD));
             cell.HorizontalAlignment = Element.ALIGN_CENTER;
             cell.Colspan             = 2;
             table.AddCell(cell);
             if (!string.IsNullOrEmpty(movie.OriginalTitle))
             {
                 cell                     = new PdfPCell(PojoToElementFactory.GetOriginalTitlePhrase(movie));
                 cell.Colspan             = 2;
                 cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                 table.AddCell(cell);
             }
             List <Director> directors = movie.Directors;
             cell                   = new PdfPCell(new Phrase("Directors:"));
             cell.Rowspan           = directors.Count;
             cell.VerticalAlignment = Element.ALIGN_MIDDLE;
             table.AddCell(cell);
             int count = 0;
             foreach (Director pojo in directors)
             {
                 cell        = new PdfPCell(PojoToElementFactory.GetDirectorPhrase(pojo));
                 cell.Indent = (10 * count++);
                 table.AddCell(cell);
             }
             table.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
             table.AddCell("Year:");
             table.AddCell(movie.Year.ToString());
             table.AddCell("Run length:");
             table.AddCell(movie.Duration.ToString());
             List <Country> countries = movie.Countries;
             cell                   = new PdfPCell(new Phrase("Countries:"));
             cell.Rowspan           = countries.Count;
             cell.VerticalAlignment = Element.ALIGN_BOTTOM;
             table.AddCell(cell);
             table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
             foreach (Country country in countries)
             {
                 table.AddCell(country.Name);
             }
             document.Add(table);
         }
     }
 }
Example #4
0
// ===========================================================================
        public override void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                IEnumerable <Movie> movies = PojoFactory.GetMovies();
                foreach (Movie movie in movies)
                {
                    // Create a paragraph with the title
                    Paragraph title = new Paragraph(
                        PojoToElementFactory.GetMovieTitlePhrase(movie)
                        );
                    title.Alignment = Element.ALIGN_LEFT;
                    document.Add(title);
                    // Add the original title next to it using a dirty hack
                    if (!string.IsNullOrEmpty(movie.OriginalTitle))
                    {
                        Paragraph dummy = new Paragraph("\u00a0", FilmFonts.NORMAL);
                        dummy.Leading = -18;
                        document.Add(dummy);
                        Paragraph originalTitle = new Paragraph(
                            PojoToElementFactory.GetOriginalTitlePhrase(movie)
                            );
                        originalTitle.Alignment = Element.ALIGN_RIGHT;
                        document.Add(originalTitle);
                    }
                    // Info about the director
                    float indent = 20;
                    // Loop over the directors
                    foreach (Director pojo in movie.Directors)
                    {
                        Paragraph director = new Paragraph(
                            PojoToElementFactory.GetDirectorPhrase(pojo)
                            );
                        director.IndentationLeft = indent;
                        document.Add(director);
                        indent += 20;
                    }
                    // Info about the country
                    indent = 20;
                    // Loop over the countries
                    foreach (Country pojo in movie.Countries)
                    {
                        Paragraph country = new Paragraph(
                            PojoToElementFactory.GetCountryPhrase(pojo)
                            );
                        country.Alignment        = Element.ALIGN_RIGHT;
                        country.IndentationRight = indent;
                        document.Add(country);
                        indent += 20;
                    }
                    // Extra info about the movie
                    Paragraph info = CreateYearAndDuration(movie);
                    info.Alignment    = Element.ALIGN_CENTER;
                    info.SpacingAfter = 36;
                    document.Add(info);
                }
            }
        }
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         Director director;
         using (var c = AdoDB.Provider.CreateConnection())
         {
             c.ConnectionString = AdoDB.CS;
             using (DbCommand cmd = c.CreateCommand())
             {
                 cmd.CommandText = SQL;
                 c.Open();
                 using (var r = cmd.ExecuteReader())
                 {
                     while (r.Read())
                     {
                         // create a paragraph for the director
                         director = PojoFactory.GetDirector(r);
                         Paragraph p = new Paragraph(
                             PojoToElementFactory.GetDirectorPhrase(director));
                         // add a dotted line separator
                         p.Add(new Chunk(new DottedLineSeparator()));
                         // adds the number of movies of this director
                         p.Add(string.Format("movies: {0}", Convert.ToInt32(r["c"])));
                         document.Add(p);
                         // Creates a list
                         List list = new List(List.ORDERED);
                         list.IndentationLeft  = 36;
                         list.IndentationRight = 36;
                         // Gets the movies of the current director
                         var      director_id = Convert.ToInt32(r["id"]);
                         ListItem movieitem;
                         // LINQ allows us to on sort any movie object property inline;
                         // let's sort by Movie.Year, Movie.Title
                         var by_year = from m in PojoFactory.GetMovies(director_id)
                                       orderby m.Year, m.Title
                         select m;
                         // loops over the movies
                         foreach (Movie movie in by_year)
                         {
                             // creates a list item with a movie title
                             movieitem = new ListItem(movie.MovieTitle);
                             // adds a vertical position mark as a separator
                             movieitem.Add(new Chunk(new VerticalPositionMark()));
                             var yr = movie.Year;
                             // adds the year the movie was produced
                             movieitem.Add(new Chunk(yr.ToString()));
                             // add an arrow to the right if the movie dates from 2000 or later
                             if (yr > 1999)
                             {
                                 movieitem.Add(PositionedArrow.RIGHT);
                             }
                             // add the list item to the list
                             list.Add(movieitem);
                         }
                         // add the list to the document
                         document.Add(list);
                     }
                 }
             }
         }
     }
 }
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         Director director;
         // creating separators
         LineSeparator line
             = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);
         Paragraph stars = new Paragraph(20);
         stars.Add(new Chunk(StarSeparator.LINE));
         stars.SpacingAfter = 30;
         using (var c = AdoDB.Provider.CreateConnection())
         {
             c.ConnectionString = AdoDB.CS;
             using (DbCommand cmd = c.CreateCommand())
             {
                 cmd.CommandText = SQL;
                 c.Open();
                 using (var r = cmd.ExecuteReader())
                 {
                     while (r.Read())
                     {
                         // get the director object and use it in a Paragraph
                         director = PojoFactory.GetDirector(r);
                         Paragraph p = new Paragraph(
                             PojoToElementFactory.GetDirectorPhrase(director));
                         // if there are more than 2 movies for this director
                         // an arrow is added to the left
                         var count = Convert.ToInt32(r["c"]);
                         if (count > 2)
                         {
                             p.Add(PositionedArrow.LEFT);
                         }
                         p.Add(line);
                         // add the paragraph with the arrow to the document
                         document.Add(p);
                         // Get the movies of the director
                         var director_id = Convert.ToInt32(r["id"]);
                         // LINQ allows us to sort on any movie object property inline;
                         // let's sort by Movie.Year, Movie.Title
                         var by_year = from m in PojoFactory.GetMovies(director_id)
                                       orderby m.Year, m.Title
                         select m;
                         foreach (Movie movie in by_year)
                         {
                             p = new Paragraph(movie.MovieTitle);
                             p.Add(": ");
                             p.Add(new Chunk(movie.Year.ToString()));
                             if (movie.Year > 1999)
                             {
                                 p.Add(PositionedArrow.RIGHT);
                             }
                             document.Add(p);
                         }
                         // add a star separator after the director info is added
                         document.Add(stars);
                     }
                 }
             }
         }
     }
 }
Example #7
0
        // ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document())
            {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                Director director;
                // creates line separators
                Chunk CONNECT = new Chunk(
                    new LineSeparator(0.5f, 95, BaseColor.BLUE, Element.ALIGN_CENTER, 3.5f)
                    );
                LineSeparator UNDERLINE = new LineSeparator(
                    1, 100, null, Element.ALIGN_CENTER, -2
                    );
                // creates tabs
                Chunk tab1 = new Chunk(new VerticalPositionMark(), 200, true);
                Chunk tab2 = new Chunk(new VerticalPositionMark(), 350, true);
                Chunk tab3 = new Chunk(new DottedLineSeparator(), 450, true);

                using (var c = AdoDB.Provider.CreateConnection())
                {
                    c.ConnectionString = AdoDB.CS;
                    using (DbCommand cmd = c.CreateCommand())
                    {
                        cmd.CommandText = SQL;
                        c.Open();
                        using (var r = cmd.ExecuteReader())
                        {
                            // loops over the directors
                            while (r.Read())
                            {
                                // creates a paragraph with the director name
                                director = PojoFactory.GetDirector(r);
                                Paragraph p = new Paragraph(
                                    PojoToElementFactory.GetDirectorPhrase(director));
                                // adds a separator
                                p.Add(CONNECT);
                                // adds more info about the director
                                p.Add(string.Format("movies: {0}", Convert.ToInt32(r["c"])));
                                // adds a separator
                                p.Add(UNDERLINE);
                                // adds the paragraph to the document
                                document.Add(p);
                                // gets all the movies of the current director
                                var director_id = Convert.ToInt32(r["id"]);
                                // LINQ allows us to sort on any movie object property inline;
                                // let's sort by Movie.Year, Movie.Title
                                var by_year = from m in PojoFactory.GetMovies(director_id)
                                              orderby m.Year, m.Title
                                select m;
                                // loops over the movies
                                foreach (Movie movie in by_year)
                                {
                                    // create a Paragraph with the movie title
                                    p = new Paragraph(movie.MovieTitle);
                                    // insert a tab
                                    p.Add(new Chunk(tab1));
                                    // add the original title
                                    var mt = movie.OriginalTitle;
                                    if (mt != null)
                                    {
                                        p.Add(new Chunk(mt));
                                    }
                                    // insert a tab
                                    p.Add(new Chunk(tab2));
                                    // add the run length of the movie
                                    p.Add(new Chunk(string.Format("{0} minutes", movie.Duration)));
                                    // insert a tab
                                    p.Add(new Chunk(tab3));
                                    // add the production year of the movie
                                    p.Add(new Chunk(
                                              string.Format("{0}", movie.Year.ToString())
                                              ));
                                    // add the paragraph to the document
                                    document.Add(p);
                                }
                                document.Add(Chunk.NEWLINE);
                            }
                        }
                    }
                }
            }
        }