// --------------------------------------------------------------------------- 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(); } } }
// --------------------------------------------------------------------------- /** * 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()); } }
// =========================================================================== public override void Write(Stream stream) { // step 1 using (Document document = new Document(PageSize.A4.Rotate())) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 PdfContentByte over = writer.DirectContent; PdfContentByte under = writer.DirectContentUnder; locations = PojoFactory.GetLocations(); PdfTemplate t_under = under.CreateTemplate( PageSize.A4.Height, PageSize.A4.Width ); DrawTimeTable(t_under); PdfTemplate t_over = over.CreateTemplate( PageSize.A4.Height, PageSize.A4.Width ); DrawTimeSlots(t_over); DrawInfo(t_over); List <string> days = PojoFactory.GetDays(); List <Screening> screenings; int d = 1; foreach (string day in days) { over.AddTemplate(t_over, 0, 0); under.AddTemplate(t_under, 0, 0); DrawDateInfo(day, d++, over); screenings = PojoFactory.GetScreenings(day); foreach (Screening screening in screenings) { DrawBlock(screening, under, over); DrawMovieInfo(screening, over); } document.NewPage(); } } }
// --------------------------------------------------------------------------- /** * Manipulates a PDF file src with the file dest as result * @param src the original PDF */ public virtual byte[] ManipulatePdf(byte[] src) { locations = PojoFactory.GetLocations(); // Create a reader PdfReader reader = new PdfReader(src); using (MemoryStream ms = new MemoryStream()) { // Create a stamper using (PdfStamper stamper = new PdfStamper(reader, ms)) { // Add the annotations int page = 1; Rectangle rect; PdfAnnotation annotation; Movie movie; foreach (string day in PojoFactory.GetDays()) { foreach (Screening screening in PojoFactory.GetScreenings(day)) { movie = screening.movie; rect = GetPosition(screening); annotation = PdfAnnotation.CreateText( stamper.Writer, rect, movie.MovieTitle, string.Format(INFO, movie.Year, movie.Duration), false, "Help" ); annotation.Color = new BaseColor( System.Drawing.ColorTranslator.FromHtml("#" + movie.entry.category.color) ); stamper.AddAnnotation(annotation, page); } page++; } } return(ms.ToArray()); } }
// --------------------------------------------------------------------------- /** * Manipulates a PDF file src with the file dest as result * @param src the original PDF */ public override byte[] ManipulatePdf(byte[] src) { locations = PojoFactory.GetLocations(); // Create a reader PdfReader reader = new PdfReader(src); using (MemoryStream ms = new MemoryStream()) { // Create a stamper using (PdfStamper stamper = new PdfStamper(reader, ms)) { // Loop over the days and screenings int page = 1; Rectangle rect; float top; PdfAnnotation annotation; Movie movie; foreach (string day in PojoFactory.GetDays()) { foreach (Screening screening in PojoFactory.GetScreenings(day)) { rect = GetPosition(screening); movie = screening.movie; // Annotation for press previews if (screening.Press) { annotation = PdfAnnotation.CreateStamp( stamper.Writer, rect, "Press only", "NotForPublicRelease" ); annotation.Color = BaseColor.BLACK; annotation.Flags = PdfAnnotation.FLAGS_PRINT; } // Annotation for screenings that are sold out else if (IsSoldOut(screening)) { top = reader.GetPageSizeWithRotation(page).Top; annotation = PdfAnnotation.CreateLine( stamper.Writer, rect, "SOLD OUT", top - rect.Top, rect.Right, top - rect.Bottom, rect.Left ); annotation.Title = movie.MovieTitle; annotation.Color = BaseColor.WHITE; annotation.Flags = PdfAnnotation.FLAGS_PRINT; annotation.BorderStyle = new PdfBorderDictionary( 5, PdfBorderDictionary.STYLE_SOLID ); } // Annotation for screenings with tickets available else { annotation = PdfAnnotation.CreateSquareCircle( stamper.Writer, rect, "Tickets available", true ); annotation.Title = movie.MovieTitle; annotation.Color = BaseColor.BLUE; annotation.Flags = PdfAnnotation.FLAGS_PRINT; annotation.Border = new PdfBorderArray( 0, 0, 2, new PdfDashPattern() ); } stamper.AddAnnotation(annotation, page); } page++; } } return(ms.ToArray()); } }