Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
                }
            }
        }