Exemple #1
0
// ===========================================================================
        public void Write(Stream stream)
        {
            string RESOURCE = Utility.ResourcePosters;

            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                Rectangle rect = new Rectangle(0, 806, 36, 842);
                rect.BackgroundColor = BaseColor.RED;
                document.Add(rect);
                // step 4
                IEnumerable <Movie> movies = PojoFactory.GetMovies();
                foreach (Movie movie in movies)
                {
                    document.Add(new Paragraph(movie.MovieTitle));
                    // Add an image
                    document.Add(
                        Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg"))
                        );
                }
            }
        }
Exemple #2
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
                int                 epoch       = -1;
                int                 currentYear = 0;
                Paragraph           title       = null;
                Chapter             chapter     = null;
                Section             section     = null;
                Section             subsection  = null;
                IEnumerable <Movie> movies      = PojoFactory.GetMovies(true);
                // loop over the movies
                foreach (Movie movie in movies)
                {
                    int yr = movie.Year;
                    // add the chapter if we're in a new epoch
                    if (epoch < (yr - 1940) / 10)
                    {
                        epoch = (yr - 1940) / 10;
                        if (chapter != null)
                        {
                            document.Add(chapter);
                        }
                        title   = new Paragraph(EPOCH[epoch], FONT[0]);
                        chapter = new Chapter(title, epoch + 1);
                    }
                    // switch to a new year
                    if (currentYear < yr)
                    {
                        currentYear = yr;
                        title       = new Paragraph(
                            string.Format("The year {0}", yr), FONT[1]
                            );
                        section = chapter.AddSection(title);
                        section.BookmarkTitle = yr.ToString();
                        section.Indentation   = 30;
                        section.BookmarkOpen  = false;
                        section.NumberStyle   = Section.NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT;
                        section.Add(new Paragraph(
                                        string.Format("Movies from the year {0}:", yr)
                                        ));
                    }
                    title      = new Paragraph(movie.Title, FONT[2]);
                    subsection = section.AddSection(title);
                    subsection.IndentationLeft = 20;
                    subsection.NumberDepth     = 1;
                    subsection.Add(new Paragraph("Duration: " + movie.Duration.ToString(), FONT[3]));
                    subsection.Add(new Paragraph("Director(s):", FONT[3]));
                    subsection.Add(PojoToElementFactory.GetDirectorList(movie));
                    subsection.Add(new Paragraph("Countries:", FONT[3]));
                    subsection.Add(PojoToElementFactory.GetCountryList(movie));
                }
                document.Add(chapter);
            }
        }
 // ---------------------------------------------------------------------------
 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();
         }
     }
 }
Exemple #4
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);
        }
Exemple #5
0
// ---------------------------------------------------------------------------
        public virtual void Write(Stream stream)
        {
            using (ZipFile zip = new ZipFile()) {
                // Get the movies
                IEnumerable <Movie> movies = PojoFactory.GetMovies();
                string datasheet           = Path.Combine(Utility.ResourcePdf, DATASHEET);
                string className           = this.ToString();
                // Fill out the data sheet form with data
                foreach (Movie movie in movies)
                {
                    if (movie.Year < 2007)
                    {
                        continue;
                    }
                    PdfReader reader = new PdfReader(datasheet);
                    string    dest   = string.Format(RESULT, movie.Imdb);
                    using (MemoryStream ms = new MemoryStream()) {
                        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
                            Fill(stamper.AcroFields, movie);
                            if (movie.Year == 2007)
                            {
                                stamper.FormFlattening = true;
                            }
                        }
                        zip.AddEntry(dest, ms.ToArray());
                    }
                }
                zip.AddFile(datasheet, "");
                zip.Save(stream);
            }
        }
Exemple #6
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
         // Create a table and fill it with movies
         IEnumerable <Movie> movies = PojoFactory.GetMovies(3);
         PdfPTable           table  = new PdfPTable(new float[] { 1, 5, 5, 1 });
         foreach (Movie movie in movies)
         {
             table.AddCell(movie.Year.ToString());
             table.AddCell(movie.MovieTitle);
             table.AddCell(movie.OriginalTitle);
             table.AddCell(movie.Duration.ToString());
         }
         // set the total width of the table
         table.TotalWidth = 600;
         PdfContentByte canvas = writer.DirectContent;
         // draw the first three columns on one page
         table.WriteSelectedRows(0, 2, 0, -1, 236, 806, canvas);
         document.NewPage();
         // draw the next three columns on the next page
         table.WriteSelectedRows(2, -1, 0, -1, 36, 806, canvas);
     }
 }
Exemple #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
                var SQL =
                    @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c
  FROM film_country c, film_movie_country mc
  WHERE c.id = mc.country_id
  GROUP BY mc.country_id, country ORDER BY c DESC";
                // Create a list for the countries
                List list = new List(List.ORDERED);
                list.First = 9;
                // loop over the countries
                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 list item for the country
                                ListItem item = new ListItem(
                                    string.Format("{0}: {1} movies",
                                                  r["country"].ToString(), r["c"].ToString()
                                                  )
                                    );
                                // Create a list for the movies
                                List movielist = new List();
                                movielist.ListSymbol = new Chunk("Movie: ", FilmFonts.BOLD);
                                foreach (Movie movie in
                                         PojoFactory.GetMovies(r["country_id"].ToString())
                                         )
                                {
                                    ListItem movieitem = new ListItem(movie.MovieTitle);
                                    // Create a list for the directors
                                    List directorlist = new ZapfDingbatsList(42);
                                    foreach (Director director in movie.Directors)
                                    {
                                        directorlist.Add(String.Format("{0}, {1}",
                                                                       director.Name, director.GivenName
                                                                       ));
                                    }
                                    movieitem.Add(directorlist);
                                    movielist.Add(movieitem);
                                }
                                item.Add(movielist);
                                list.Add(item);
                            }
                            document.Add(list);
                        }
                    }
                }
            }
        }
// ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         * @param stream Stream for the new PDF document
         */
        public void CreatePdf(Stream stream)
        {
            string RESOURCE = Utility.ResourcePosters;

            // 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;
                PdfAnnotation annotation;
                foreach (Movie movie in PojoFactory.GetMovies())
                {
                    phrase     = new Phrase(movie.MovieTitle);
                    chunk      = new Chunk("\u00a0\u00a0");
                    annotation = PdfAnnotation.CreateFileAttachment(
                        writer, null,
                        movie.MovieTitle, null,
                        Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
                        string.Format("img_{0}.jpg", movie.Imdb)
                        );
                    annotation.Put(PdfName.NAME, new PdfString("Paperclip"));
                    chunk.SetAnnotation(annotation);
                    phrase.Add(chunk);
                    document.Add(phrase);
                    document.Add(PojoToElementFactory.GetDirectorList(movie));
                    document.Add(PojoToElementFactory.GetCountryList(movie));
                }
            }
        }
// ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document(PageSize.A5.Rotate())) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                writer.PdfVersion        = PdfWriter.VERSION_1_5;
                writer.ViewerPreferences = PdfWriter.PageModeFullScreen;
                writer.PageEvent         = new TransitionDuration();
                // step 3
                document.Open();
                // step 4
                IEnumerable <Movie> movies = PojoFactory.GetMovies();
                Image     img;
                PdfPCell  cell;
                PdfPTable table    = new PdfPTable(6);
                string    RESOURCE = Utility.ResourcePosters;
                foreach (Movie movie in movies)
                {
                    img         = Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg"));
                    cell        = new PdfPCell(img, true);
                    cell.Border = PdfPCell.NO_BORDER;
                    table.AddCell(cell);
                }
                document.Add(table);
            }
        }
        // ---------------------------------------------------------------------------

        /**
         * 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);
        }
Exemple #11
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());
            }
        }
Exemple #12
0
// ---------------------------------------------------------------------------

        /**
         * Manipulates a PDF file src with the file dest as result
         * @param src the original PDF
         */
        public byte[] ManipulatePdf(byte[] src)
        {
            // Create a list with bookmarks
            List <Dictionary <string, object> > outlines =
                new List <Dictionary <string, object> >();
            Dictionary <string, object> map = new Dictionary <string, object>();

            outlines.Add(map);
            map.Add("Title", "Calendar");
            List <Dictionary <string, object> > kids =
                new List <Dictionary <string, object> >();

            map.Add("Kids", kids);
            int page = 1;
            IEnumerable <string> days = PojoFactory.GetDays();

            foreach (string day in days)
            {
                Dictionary <string, object> kid = new Dictionary <string, object>();
                kids.Add(kid);
                kid["Title"]  = day;
                kid["Action"] = "GoTo";
                kid["Page"]   = String.Format("{0} Fit", page++);
            }
            // Create a reader
            PdfReader reader = new PdfReader(src);

            using (MemoryStream ms = new MemoryStream()) {
                // Create a stamper
                using (PdfStamper stamper = new PdfStamper(reader, ms)) {
                    stamper.Outlines = outlines;
                }
                return(ms.ToArray());
            }
        }
Exemple #13
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));
                }
            }
        }
// ---------------------------------------------------------------------------

        /**
         * Creates a list with movies in HTML and PDF simultaneously.
         * @param pdf a path to the resulting PDF file
         * @param html a path to the resulting HTML file
         */
        public byte[] CreateHtmlAndPdf(Stream stream)
        {
            // store the HTML in a string and dump on separate page
            Html.Append("<html>\n<body>");
            Html.Append(Environment.NewLine);
            using (MemoryStream ms = new MemoryStream()) {
                // step 1
                using (Document document = new Document()) {
                    // step 2
                    PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    String snippet;
                    foreach (Movie movie in PojoFactory.GetMovies())
                    {
                        // create the snippet
                        snippet = CreateHtmlSnippet(movie);
                        // use the snippet for the HTML page
                        Html.Append(snippet);
                        // use the snippet for the PDF document
                        List <IElement> objects = HTMLWorker.ParseToList(
                            new StringReader(snippet), styles, providers
                            );
                        foreach (IElement element in objects)
                        {
                            document.Add(element);
                        }
                    }
                }
                Html.Append("</body>\n</html>");
                return(ms.ToArray());
            }
        }
Exemple #15
0
        // ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         * @param stationary byte array of the new PDF document
         */
        public byte[] CreatePdf(byte[] stationary)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                // step 1
                using (Document document = new Document(PageSize.A4, 36, 36, 72, 36))
                {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    //writer.CloseStream = false;
                    UseStationary(writer, stationary);
                    // step 3
                    document.Open();
                    // step 4
                    string SQL = "SELECT country, id FROM film_country ORDER BY country";
                    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())
                                {
                                    document.Add(new Paragraph(
                                                     r["country"].ToString(), FilmFonts.BOLD
                                                     ));
                                    document.Add(Chunk.NEWLINE);
                                    string id = r["id"].ToString();
                                    foreach (Movie movie in PojoFactory.GetMovies(id, true))
                                    {
                                        document.Add(new Paragraph(
                                                         movie.MovieTitle, FilmFonts.BOLD
                                                         ));
                                        if (!string.IsNullOrEmpty(movie.OriginalTitle))
                                        {
                                            document.Add(new Paragraph(
                                                             movie.OriginalTitle, FilmFonts.ITALIC
                                                             ));
                                        }
                                        document.Add(new Paragraph(
                                                         string.Format(
                                                             "Year: {0}; run length: {0} minutes",
                                                             movie.Year, movie.Duration
                                                             ),
                                                         FilmFonts.NORMAL
                                                         ));
                                        document.Add(PojoToElementFactory.GetDirectorList(movie));
                                    }
                                    document.NewPage();
                                }
                            }
                        }
                    }
                }
                return(ms.ToArray());
            }
        }
Exemple #16
0
// ---------------------------------------------------------------------------

        /**
         * Creates the PDF.
         * @return the bytes of a PDF file.
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream()) {
                using (Document document = new Document()) {
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    document.Open();
                    document.Add(new Paragraph(
                                     "This is a list of Kubrick movies available in DVD stores."
                                     ));
                    IEnumerable <Movie> movies = PojoFactory.GetMovies(1)
                                                 .Concat(PojoFactory.GetMovies(4))
                    ;
                    List   list     = new List();
                    string RESOURCE = Utility.ResourcePosters;
                    foreach (Movie movie in movies)
                    {
                        PdfAnnotation annot = PdfAnnotation.CreateFileAttachment(
                            writer, null,
                            movie.GetMovieTitle(false), null,
                            Path.Combine(RESOURCE, movie.Imdb + ".jpg"),
                            string.Format("{0}.jpg", movie.Imdb)
                            );
                        ListItem item = new ListItem(movie.GetMovieTitle(false));
                        item.Add("\u00a0\u00a0");
                        Chunk chunk = new Chunk("\u00a0\u00a0\u00a0\u00a0");
                        chunk.SetAnnotation(annot);
                        item.Add(chunk);
                        list.Add(item);
                    }
                    document.Add(list);
                }
                return(ms.ToArray());
            }
        }
        // ===========================================================================
        public void Write(Stream stream)
        {
            var SQL =
                @"SELECT DISTINCT mc.country_id, c.country, count(*) AS c 
FROM film_country c, film_movie_country mc 
  WHERE c.id = mc.country_id
GROUP BY mc.country_id, country ORDER BY c DESC";

            // step 1
            using (Document document = new Document())
            {
                // step 2
                PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                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())
                            {
                                Paragraph country = new Paragraph();
                                // the name of the country will be a destination
                                Anchor dest = new Anchor(
                                    r["country"].ToString(), FilmFonts.BOLD
                                    );
                                dest.Name = r["country_id"].ToString();
                                country.Add(dest);
                                country.Add(string.Format(": {0} movies", r["c"].ToString()));
                                document.Add(country);
                                // loop over the movies
                                foreach (Movie movie in
                                         PojoFactory.GetMovies(r["country_id"].ToString()))
                                {
                                    // the movie title will be an external link
                                    Anchor imdb = new Anchor(movie.MovieTitle);
                                    imdb.Reference = string.Format(
                                        "http://www.imdb.com/title/tt{0}/", movie.Imdb
                                        );
                                    document.Add(imdb);
                                    document.Add(Chunk.NEWLINE);
                                }
                                document.NewPage();
                            }
                            // Create an internal link to the first page
                            Anchor toUS = new Anchor("Go back to the first page.");
                            toUS.Reference = "#US";
                            document.Add(toUS);
                        }
                    }
                }
            }
        }
Exemple #18
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);
         }
     }
 }
Exemple #19
0
 public virtual void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4, 36, 36, 54, 36))
     {
         // step 2
         PdfWriter   writer = PdfWriter.GetInstance(document, stream);
         TableHeader tevent = new TableHeader();
         writer.PageEvent = tevent;
         // step 3
         document.Open();
         // step 4
         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())
                     {
                         tevent.Header = r["country"].ToString();
                         // 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(
                             r["id"].ToString()
                             )
                                       orderby m.Year, m.Title
                         select m
                         ;
                         foreach (Movie movie in by_year)
                         {
                             document.Add(new Paragraph(
                                              movie.MovieTitle, FilmFonts.BOLD
                                              ));
                             if (!string.IsNullOrEmpty(movie.OriginalTitle))
                             {
                                 document.Add(
                                     new Paragraph(movie.OriginalTitle, FilmFonts.ITALIC)
                                     );
                             }
                             document.Add(new Paragraph(
                                              String.Format("Year: {0}; run length: {1} minutes",
                                                            movie.Year, movie.Duration
                                                            ), FilmFonts.NORMAL
                                              ));
                             document.Add(PojoToElementFactory.GetDirectorList(movie));
                         }
                         document.NewPage();
                     }
                 }
             }
         }
     }
 }
 // ===========================================================================
 public 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
         ColumnText    column = new ColumnText(writer.DirectContent);
         List <string> days   = PojoFactory.GetDays();
         // COlumn definition
         float[][] x =
         {
             new float[] { document.Left,        document.Left + 380 },
             new float[] { document.Right - 380, document.Right      }
         };
         // Loop over the festival days
         foreach (string day in days)
         {
             // add content to the column
             column.AddElement(GetTable(day));
             int   count  = 0;
             float height = 0;
             // iText-ONLY, 'Initial value of the status' => 0
             // iTextSharp **DOES NOT** include this member variable
             // int status = ColumnText.START_COLUMN;
             int status = 0;
             // render the column as long as it has content
             while (ColumnText.HasMoreText(status))
             {
                 // add the top-level header to each new page
                 if (count == 0)
                 {
                     height = AddHeaderTable(document, day, writer.PageNumber);
                 }
                 // set the dimensions of the current column
                 column.SetSimpleColumn(
                     x[count][0], document.Bottom,
                     x[count][1], document.Top - height - 10
                     );
                 // render as much content as possible
                 status = column.Go();
                 // go to a new page if you've reached the last column
                 if (++count > 1)
                 {
                     count = 0;
                     document.NewPage();
                 }
             }
             document.NewPage();
         }
     }
 }
Exemple #21
0
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4))
     {
         // step 2
         PdfWriter writer = PdfWriter.GetInstance(document, stream);
         // step 3
         document.Open();
         // step 4
         PdfContentByte canvas = writer.DirectContent;
         // Create a reusable XObject
         PdfTemplate celluloid = canvas.CreateTemplate(595, 84.2f);
         celluloid.Rectangle(8, 8, 579, 68);
         for (float f = 8.25f; f < 581; f += 6.5f)
         {
             celluloid.RoundRectangle(f, 8.5f, 6, 3, 1.5f);
             celluloid.RoundRectangle(f, 72.5f, 6, 3, 1.5f);
         }
         celluloid.SetGrayFill(0.1f);
         celluloid.EoFill();
         writer.ReleaseTemplate(celluloid);
         // Add the XObject ten times
         for (int i = 0; i < 10; i++)
         {
             canvas.AddTemplate(celluloid, 0, i * 84.2f);
         }
         // Add the movie posters
         Image      img;
         Annotation annotation;
         float      x        = 11.5f;
         float      y        = 769.7f;
         string     RESOURCE = Utility.ResourcePosters;
         foreach (Movie movie in PojoFactory.GetMovies())
         {
             img = Image.GetInstance(Path.Combine(RESOURCE, movie.Imdb + ".jpg"));
             img.ScaleToFit(1000, 60);
             img.SetAbsolutePosition(x + (45 - img.ScaledWidth) / 2, y);
             annotation = new Annotation(
                 0, 0, 0, 0,
                 string.Format(IMDB, movie.Imdb)
                 );
             img.Annotation = annotation;
             canvas.AddImage(img);
             x += 48;
             if (x > 578)
             {
                 x  = 11.5f;
                 y -= 84.2f;
             }
         }
     }
 }
Exemple #22
0
 /*
  * end inner class
  */
 // ---------------------------------------------------------------------------
 public void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document())
     {
         // step 2
         PdfWriter   writer = PdfWriter.GetInstance(document, stream);
         GenericTags gevent = new GenericTags();
         writer.PageEvent = gevent;
         writer.PageEvent = new ParagraphPositions();
         // step 3
         document.Open();
         // step 4
         Font bold   = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD);
         Font italic = new Font(Font.FontFamily.HELVETICA, 11, Font.ITALIC);
         Font white  = new Font(
             Font.FontFamily.HELVETICA, 12,
             Font.BOLD | Font.ITALIC,
             BaseColor.WHITE
             );
         Paragraph p;
         Chunk     c;
         foreach (Movie movie in PojoFactory.GetMovies(true))
         {
             p = new Paragraph(22);
             c = new Chunk(String.Format("{0} ", movie.Year), bold);
             c.SetGenericTag("strip");
             p.Add(c);
             c = new Chunk(movie.MovieTitle);
             c.SetGenericTag(movie.Year.ToString());
             p.Add(c);
             c = new Chunk(
                 String.Format(" ({0} minutes)  ", movie.Duration),
                 italic
                 );
             p.Add(c);
             c = new Chunk("IMDB", white);
             c.SetAnchor("http://www.imdb.com/title/tt" + movie.Imdb);
             c.SetGenericTag("ellipse");
             p.Add(c);
             document.Add(p);
         }
         document.NewPage();
         writer.PageEvent = null;
         foreach (string entry in gevent.years.Keys)
         {
             p = new Paragraph(String.Format(
                                   "{0}: {1} movie(s)", entry, gevent.years[entry]
                                   ));
             document.Add(p);
         }
     }
 }
 // ===========================================================================
 public override 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
         PdfContentByte canvas = writer.DirectContent;
         DrawRectangles(canvas);
         ColumnText ct = new ColumnText(canvas);
         ct.Alignment = Element.ALIGN_JUSTIFIED;
         ct.Leading   = 14;
         int column = 0;
         ct.SetColumns(
             new float[] { 36, 806, 36, 670, 108, 670, 108, 596, 36, 596, 36, 36 },
             new float[] { 296, 806, 296, 484, 259, 484, 259, 410, 296, 410, 296, 36 }
             );
         ct.SetColumns(LEFT[column], RIGHT[column]);
         // ct.SetColumns(LEFT[column], RIGHT[column]);
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int    status = 0;
         Phrase p;
         float  y;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y = ct.YLine;
             p = CreateMovieInformation(movie);
             ct.AddText(p);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                     DrawRectangles(canvas);
                 }
                 ct.SetColumns(LEFT[column], RIGHT[column]);
                 y = 806;
             }
             ct.YLine = y;
             ct.SetText(p);
             status = ct.Go();
         }
     }
 }
 // ---------------------------------------------------------------------------
 public 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
         ColumnText ct     = new ColumnText(writer.DirectContent);
         int        column = 0;
         ct.SetSimpleColumn(
             COLUMNS[column, 0], COLUMNS[column, 1],
             COLUMNS[column, 2], COLUMNS[column, 3]
             );
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int   status = 0;
         float y;
         Image img;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y   = ct.YLine;
             img = Image.GetInstance(
                 Path.Combine(RESOURCE, movie.Imdb + ".jpg")
                 );
             img.ScaleToFit(80, 1000);
             AddContent(ct, movie, img);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = (column + 1) % 4;
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column, 0], COLUMNS[column, 1],
                     COLUMNS[column, 2], COLUMNS[column, 3]
                     );
                 y = COLUMNS[column, 3];
             }
             ct.YLine = y;
             ct.SetText(null);
             AddContent(ct, movie, img);
             status = ct.Go();
         }
     }
 }
Exemple #25
0
// ---------------------------------------------------------------------------
        public string CreateXML()
        {
            StringBuilder SB = new StringBuilder();

            SB.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            SB.Append("<movies>\n");
            foreach (Movie movie in PojoFactory.GetMovies())
            {
                SB.Append(GetXml(movie));
            }
            SB.Append("</movies>");
            return(SB.ToString());
        }
 // ---------------------------------------------------------------------------
 public override void Write(Stream stream)
 {
     // step 1
     using (Document document = new Document(PageSize.A4, 36, 36, 54, 36))
     {
         // step 2
         PdfWriter   writer = PdfWriter.GetInstance(document, stream);
         TableHeader tevent = new TableHeader();
         writer.PageEvent = tevent;
         writer.PageEvent = new Watermark();
         // step 3
         document.Open();
         // step 4
         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())
                     {
                         tevent.Header = r["country"].ToString();
                         foreach (Movie movie
                                  in PojoFactory.GetMovies(r["id"].ToString(), true))
                         {
                             document.Add(new Paragraph(
                                              movie.MovieTitle, FilmFonts.BOLD
                                              ));
                             if (!string.IsNullOrEmpty(movie.OriginalTitle))
                             {
                                 document.Add(
                                     new Paragraph(movie.OriginalTitle, FilmFonts.ITALIC)
                                     );
                             }
                             document.Add(new Paragraph(
                                              String.Format("Year: {0}; run length: {1} minutes",
                                                            movie.Year, movie.Duration
                                                            ), FilmFonts.NORMAL
                                              ));
                             document.Add(PojoToElementFactory.GetDirectorList(movie));
                         }
                         document.NewPage();
                     }
                 }
             }
         }
     }
 }
        // ---------------------------------------------------------------------------

        /**
         * Creates a PDF document.
         */
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                // step 1
                using (Document document = new Document())
                {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    PdfOutline          root = writer.RootOutline;
                    PdfOutline          movieBookmark;
                    PdfOutline          link;
                    String              title;
                    IEnumerable <Movie> movies = PojoFactory.GetMovies();
                    foreach (Movie movie in movies)
                    {
                        title = movie.MovieTitle;
                        if ("3-Iron".Equals(title))
                        {
                            title = "\ube48\uc9d1";
                        }
                        movieBookmark = new PdfOutline(root,
                                                       new PdfDestination(
                                                           PdfDestination.FITH, writer.GetVerticalPosition(true)
                                                           ),
                                                       title, true
                                                       );
                        movieBookmark.Style = Font.BOLD;
                        link = new PdfOutline(movieBookmark,
                                              new PdfAction(String.Format(RESOURCE, movie.Imdb)),
                                              "link to IMDB"
                                              );
                        link.Color = BaseColor.BLUE;
                        new PdfOutline(movieBookmark,
                                       PdfAction.JavaScript(
                                           String.Format(INFO, movie.Year, movie.Duration),
                                           writer
                                           ),
                                       "instant info"
                                       );
                        document.Add(new Paragraph(movie.MovieTitle));
                        document.Add(PojoToElementFactory.GetDirectorList(movie));
                        document.Add(PojoToElementFactory.GetCountryList(movie));
                    }
                }
                return(ms.ToArray());
            }
        }
 // ===========================================================================
 public override 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
         ColumnText ct = new ColumnText(writer.DirectContent)
         {
             Alignment           = Element.ALIGN_JUSTIFIED,
             ExtraParagraphSpace = 6,
             Leading             = 14,
             Indent         = 10,
             RightIndent    = 3,
             SpaceCharRatio = PdfWriter.NO_SPACE_CHAR_RATIO
         };
         int column = 0;
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int status = 0;
         ct.SetSimpleColumn(
             COLUMNS[column][0], COLUMNS[column][1],
             COLUMNS[column][2], COLUMNS[column][3]
             );
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             ct.AddText(CreateMovieInformation(movie));
             status = ct.Go();
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column][0], COLUMNS[column][1],
                     COLUMNS[column][2], COLUMNS[column][3]
                     );
                 ct.YLine = COLUMNS[column][3];
                 status   = ct.Go();
             }
         }
     }
 }
Exemple #29
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);
        }
 // ===========================================================================
 public override 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
         ColumnText ct     = new ColumnText(writer.DirectContent);
         int        column = 0;
         ct.SetSimpleColumn(
             COLUMNS[column][0], COLUMNS[column][1],
             COLUMNS[column][2], COLUMNS[column][3]
             );
         // iText-ONLY, 'Initial value of the status' => 0
         // iTextSharp **DOES NOT** include this member variable
         // int status = ColumnText.START_COLUMN;
         int    status = 0;
         Phrase p;
         float  y;
         IEnumerable <Movie> movies = PojoFactory.GetMovies();
         foreach (Movie movie in movies)
         {
             y = ct.YLine;
             p = CreateMovieInformation(movie);
             ct.AddText(p);
             status = ct.Go(true);
             if (ColumnText.HasMoreText(status))
             {
                 column = Math.Abs(column - 1);
                 if (column == 0)
                 {
                     document.NewPage();
                 }
                 ct.SetSimpleColumn(
                     COLUMNS[column][0], COLUMNS[column][1],
                     COLUMNS[column][2], COLUMNS[column][3]
                     );
                 y = COLUMNS[column][3];
             }
             ct.YLine = y;
             ct.SetText(p);
             status = ct.Go(false);
         }
     }
 }