// ---------------------------------------------------------------------------    
 /**
  * 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;
 }
 // ---------------------------------------------------------------------------    
 /**
  * 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;
 }
 // ---------------------------------------------------------------------------
 /**
  * Creates a list with countries.
  * @param movie a Movie object
  * @return a List object
  */
 public static List GetCountryList(Movie movie)
 {
     var list = new List();
     foreach (Country country in movie.Countries)
     {
         list.Add(country.Name);
     }
     return list;
 }
 // ---------------------------------------------------------------------------    
 /**
  * Creates a Paragraph containing information about the year
  * and the duration of a movie.
  * @param    movie    the movie for which you want to create a Paragraph
  */
 public Paragraph CreateYearAndDuration(Movie movie)
 {
     Paragraph info = new Paragraph();
     info.Font = FilmFonts.NORMAL;
     info.Add(new Chunk("Year: ", FilmFonts.BOLDITALIC));
     info.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
     info.Add(new Chunk(" Duration: ", FilmFonts.BOLDITALIC));
     info.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
     info.Add(new Chunk(" minutes", FilmFonts.NORMAL));
     return info;
 }
 // ---------------------------------------------------------------------------
 /**
  * Creates a list with directors.
  * @param movie a Movie object
  * @return a List object
  */
 public static List GetDirectorList(Movie movie)
 {
     var list = new List();
     foreach (Director director in movie.Directors)
     {
         list.Add(string.Format(
           "{0}, {1}", director.Name, director.GivenName
         ));
     }
     return list;
 }
 // ---------------------------------------------------------------------------    
 /**
  * Fill out the fields using info from a Movie object.
  * @param form The form object
  * @param movie A movie POJO
  */
 public static void Fill(AcroFields form, Movie movie)
 {
     form.SetField("title", movie.MovieTitle);
     form.SetField("director", GetDirectors(movie));
     form.SetField("year", movie.Year.ToString());
     form.SetField("duration", movie.Duration.ToString());
     form.SetField("category", movie.entry.category.Keyword);
     foreach (Screening screening in movie.entry.Screenings)
     {
         form.SetField(screening.Location.Replace('.', '_'), "Yes");
     }
 }
 // ---------------------------------------------------------------------------    
 /**
  * Add content to a ColumnText object.
  * @param ct the ColumnText object
  * @param movie a Movie object
  * @param img the poster of the image
  */
 public void AddContent(ColumnText ct, Movie movie, Image img)
 {
     ct.AddElement(img);
     ct.AddElement(new Paragraph(movie.Title, FilmFonts.BOLD));
     if (!string.IsNullOrEmpty(movie.OriginalTitle))
     {
         ct.AddElement(new Paragraph(movie.OriginalTitle, FilmFonts.ITALIC));
     }
     ct.AddElement(PojoToElementFactory.GetDirectorList(movie));
     ct.AddElement(PojoToElementFactory.GetYearPhrase(movie));
     ct.AddElement(PojoToElementFactory.GetDurationPhrase(movie));
     ct.AddElement(PojoToElementFactory.GetCountryList(movie));
     ct.AddElement(Chunk.NEWLINE);
 }
 // ---------------------------------------------------------------------------    
 /**
  * Gets the directors from a Movie object,
  * and concatenates them in a String.
  * @param movie a Movie object
  * @return a String containing director names
  */
 public static String GetDirectors(Movie movie)
 {
     List<Director> directors = movie.Directors;
     StringBuilder buf = new StringBuilder();
     foreach (Director director in directors)
     {
         buf.Append(director.GivenName);
         buf.Append(' ');
         buf.Append(director.Name);
         buf.Append(',');
         buf.Append(' ');
     }
     int i = buf.Length;
     if (i > 0) buf.Length = i - 2;
     return buf.ToString();
 }
        // ---------------------------------------------------------------------------
        /**
         * Creates the PDF.
         * @return the bytes of a PDF file.
         */
        public byte[] CreateMoviePage(Movie movie)
        {
            using (MemoryStream ms = new MemoryStream()) {
            // step 1
            using (Document document = new Document()) {
              // step 2
              PdfWriter.GetInstance(document, ms);
              // step 3
              document.Open();
              // step 4
              Paragraph p = new Paragraph(
            movie.MovieTitle,
            FontFactory.GetFont(
              BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, 16
            )
              );
              document.Add(p);
              document.Add(Chunk.NEWLINE);
              PdfPTable table = new PdfPTable(WIDTHS);
              table.AddCell(Image.GetInstance(
            String.Format(RESOURCE, movie.Imdb)
              ));
              PdfPCell cell = new PdfPCell();
              cell.AddElement(new Paragraph("Year: " + movie.Year.ToString()));
              cell.AddElement(new Paragraph("Duration: " + movie.Duration.ToString()));
              table.AddCell(cell);
              document.Add(table);

              PdfTargetDictionary target = new PdfTargetDictionary(false);
              target.AdditionalPath = new PdfTargetDictionary(false);
              Chunk chunk = new Chunk("Go to original document");
              PdfAction action = PdfAction.GotoEmbedded(
            null, target, new PdfString("movies"), false
              );
              chunk.SetAction(action);
              document.Add(chunk);
            }
            return ms.ToArray();
              }
        }
 // ---------------------------------------------------------------------------    
 /**
  * Add content to a ColumnText object.
  * @param ct the ColumnText object
  * @param movie a Movie object
  * @param img the poster of the image
  */
 public void AddContent(ColumnText ct, Movie movie)
 {
     Paragraph p;
     p = new Paragraph(new Paragraph(movie.Title, FilmFonts.BOLD));
     p.Alignment = Element.ALIGN_CENTER;
     p.SpacingBefore = 16;
     ct.AddElement(p);
     if (!string.IsNullOrEmpty(movie.OriginalTitle))
     {
         p = new Paragraph(movie.OriginalTitle, FilmFonts.ITALIC);
         p.Alignment = Element.ALIGN_RIGHT;
         ct.AddElement(p);
     }
     p = new Paragraph();
     p.Add(PojoToElementFactory.GetYearPhrase(movie));
     p.Add(" ");
     p.Add(PojoToElementFactory.GetDurationPhrase(movie));
     p.Alignment = Element.ALIGN_JUSTIFIED_ALL;
     ct.AddElement(p);
     p = new Paragraph(new Chunk(new StarSeparator()));
     p.SpacingAfter = 12;
     ct.AddElement(p);
 }
Example #11
0
// ---------------------------------------------------------------------------    
    public String GetXml(Movie movie) {
      StringBuilder buf = new StringBuilder();
      buf.Append("<movie duration=\"");
      buf.Append(movie.Duration.ToString());
      buf.Append("\" imdb=\"");
      buf.Append(movie.Imdb);
      buf.Append("\" year=\"");
      buf.Append(movie.Year.ToString());
      buf.Append("\">");
      buf.Append("<title>");
      buf.Append(movie.MovieTitle);
      buf.Append("</title>");
      if (!string.IsNullOrEmpty(movie.OriginalTitle)) {
        buf.Append("<original>");
        buf.Append(movie.OriginalTitle);
        buf.Append("</original>");
      }
      buf.Append("<directors>");
      foreach (Director director in movie.Directors) {
        buf.Append("<director>");
        buf.Append(director.Name);
        buf.Append(", ");
        buf.Append(director.GivenName);
        buf.Append("</director>");
      }
      buf.Append("</directors>");
      buf.Append("<countries>");
      foreach (Country country in movie.Countries) {
        buf.Append("<country>");
        buf.Append(country.Name);
        buf.Append("</country>");
      }
      buf.Append("</countries>");
      buf.Append("</movie>\n");
      return buf.ToString();
    }    
 // ---------------------------------------------------------------------------
 /**
  * Creates a phrase with the production year of a movie.
  * @param movie a Movie object
  * @return a Phrase object
  */
 // public static Element GetYearPhrase(Movie movie) {
 public static Phrase GetYearPhrase(Movie movie)
 {
     Phrase p = new Phrase();
     p.Add(new Chunk("Year: ", FilmFonts.BOLD));
     p.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
     return p;
 }
 // ---------------------------------------------------------------------------
 /**
  * Creates a Phrase containing the original title of a Movie.
  * @param movie a Movie object
  * @return a Phrase object
  */
 public static Phrase GetOriginalTitlePhrase(Movie movie)
 {
     return string.IsNullOrEmpty(movie.OriginalTitle)
       ? new Phrase("", FilmFonts.NORMAL)
       : new Phrase(movie.OriginalTitle, FilmFonts.ITALIC)
       ;
 }
 // ===========================================================================
 /**
  * Creates a Phrase containing the title of a Movie.
  * @param movie a Movie object
  * @return a Phrase object
  */
 public static Phrase GetMovieTitlePhrase(Movie movie)
 {
     return new Phrase(movie.MovieTitle, FilmFonts.NORMAL);
 }
Example #15
0
// ---------------------------------------------------------------------------
    /**
     * Creates an HTML snippet with info about a movie.
     * @param movie the movie for which we want to create HTML
     * @return a String with HTML code
     */
    public override String CreateHtmlSnippet(Movie movie) {
      StringBuilder buf = new StringBuilder("<table width='500'>\n<tr>\n");
      buf.Append("\t<td><img src='");
      buf.Append(movie.Imdb);
      buf.Append(".jpg' /></td>\t<td>\n");
      buf.Append(base.CreateHtmlSnippet(movie));
      buf.Append("\t</ul>\n\t</td>\n</tr>\n</table>");
      return buf.ToString();
    }    
Example #16
0
// ---------------------------------------------------------------------------    
    /**
     * Creates an HTML snippet with info about a movie.
     * @param movie the movie for which we want to create HTML
     * @return a String with HTML code
     */
    public virtual String CreateHtmlSnippet(Movie movie) {
      StringBuilder buf = new StringBuilder("\t<span class='title'>");
      buf.Append(movie.MovieTitle);
      buf.Append("</span><br />\n");
      buf.Append("\t<ul>\n");
      foreach (Country country in movie.Countries) {
        buf.Append("\t\t<li class='country'>");
        buf.Append(country.Name);
        buf.Append("</li>\n");
      }
      buf.Append("\t</ul>\n");
      buf.Append("\tYear: <i>");
      buf.Append(movie.Year.ToString());
      buf.Append(" minutes</i><br />\n");
      buf.Append("\tDuration: <i>");
      buf.Append(movie.Duration.ToString());
      buf.Append(" minutes</i><br />\n");
      buf.Append("\t<ul>\n");
      foreach (Director director in movie.Directors) {
        buf.Append("\t\t<li><span class='director'>");
        buf.Append(director.Name);
        buf.Append(", ");
        buf.Append(director.GivenName);
        buf.Append("</span></li>\n");
      }
      buf.Append("\t</ul>\n");
      return buf.ToString();
    }   
Example #17
0
// ---------------------------------------------------------------------------
    public byte[] FillTemplate(byte[] pdf, Movie movie) {
      using (MemoryStream ms = new MemoryStream()) {
        PdfReader reader = new PdfReader(pdf);
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          AcroFields form = stamper.AcroFields;
          BaseColor color = WebColors.GetRGBColor(
            "#" + movie.entry.category.color
          );
          PushbuttonField bt = form.GetNewPushbuttonFromField(POSTER);
          bt.Layout = PushbuttonField.LAYOUT_ICON_ONLY;
          bt.ProportionalIcon = true;
          bt.Image = Image.GetInstance(Path.Combine(IMAGE, movie.Imdb + ".jpg"));
          bt.BackgroundColor = color;
          form.ReplacePushbuttonField(POSTER, bt.Field);
          
          PdfContentByte canvas = stamper.GetOverContent(1);
          float size = 12;
          AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
          while (AddParagraph(CreateMovieParagraph(movie, size),
              canvas, f, true) && size > 6) 
          {
              size -= 0.2f;
          }
          AddParagraph(CreateMovieParagraph(movie, size), canvas, f, false);
          
          form.SetField(YEAR, movie.Year.ToString());
          form.SetFieldProperty(YEAR, "bgcolor", color, null);
          form.SetField(YEAR, movie.Year.ToString());
          stamper.FormFlattening = true;
        }
        return ms.ToArray();
      }
    }
 // ---------------------------------------------------------------------------
 /**
  * Creates a phrase with the run length of a movie.
  * @param movie a Movie object
  * @return a Phrase object
  */
 // public static Element getDurationPhrase(Movie movie) {
 public static Phrase GetDurationPhrase(Movie movie)
 {
     Phrase p = new Phrase();
     p.Add(new Chunk("Duration: ", FilmFonts.BOLD));
     p.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
     return p;
 }
Example #19
0
// ---------------------------------------------------------------------------
    public Paragraph CreateMovieParagraph(Movie movie, float fontsize) {
      Font normal = new Font(Font.FontFamily.HELVETICA, fontsize);
      Font bold = new Font(Font.FontFamily.HELVETICA, fontsize, Font.BOLD);
      Font italic = new Font(Font.FontFamily.HELVETICA, fontsize, Font.ITALIC);
      Paragraph p = new Paragraph(fontsize * 1.2f);
      p.Font = normal;
      p.Alignment = Element.ALIGN_JUSTIFIED;
      p.Add(new Chunk(movie.MovieTitle, bold));
      if (!string.IsNullOrEmpty(movie.OriginalTitle)) {
        p.Add(" ");
        p.Add(new Chunk(movie.OriginalTitle, italic));
      }
      p.Add(new Chunk(string.Format(
        "; run length: {0}", movie.Duration), normal
      ));
      p.Add(new Chunk("; directed by:", normal));
      foreach (Director director in movie.Directors) {
        p.Add(" ");
        p.Add(director.GivenName);
        p.Add(", ");
        p.Add(director.Name);
      }
      return p;
    }