// --------------------------------------------------------------------------- /** * 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()); } }
// --------------------------------------------------------------------------- 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 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(); } } }
// --------------------------------------------------------------------------- public void Write(Stream stream) { // step 1 using (Document document = new Document()) { // step 2 PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 List <string> days = PojoFactory.GetDays(); foreach (string day in days) { document.Add(GetTable(day)); document.NewPage(); } } }
// =========================================================================== public override void Write(Stream stream) { // step 1 using (Document document = new Document(PageSize.A4.Rotate())) { // step 2 PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 List <string> days = PojoFactory.GetDays(); foreach (string day in days) { PdfPTable table = GetTable(day); table.SplitLate = false; document.Add(table); document.NewPage(); } } }
// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document(PageSize.A4.Rotate())) { // step 2 PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 List <string> days = PojoFactory.GetDays(); IPdfPTableEvent Pevent = new AlternatingBackground(); foreach (string day in days) { PdfPTable table = GetTable(day); table.TableEvent = Pevent; document.Add(table); document.NewPage(); } } }
// =========================================================================== 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()); } }