Exemplo n.º 1
0
        public void SaveComments(string namePDF, int page)
        {
            string oldFile = namePDF;
            string newFile = "temporal.pdf";

            PdfReader  pdfReader  = new PdfReader(oldFile);
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));

            Point[] finalcoor = coorComentario.ToArray();
            for (int i = 1; i <= cantComentarios; i++)
            {
                string imageURL = directorio + "\\comment" + i + ".jpg";

                Stream inputImageStream = new FileStream(imageURL, FileMode.Open, FileAccess.Read, FileShare.Read);

                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
                //int xpos = finalcoor[i - 1].X;
                //int ypos = finalcoor[i - 1].Y;
                Console.WriteLine("estas son las coordenadas" + finalcoor[i - 1].X + " y " + finalcoor[i - 1].Y);
                int xpos = 100;
                int ypos = 100;
                iTextSharp.text.Rectangle rect     = new iTextSharp.text.Rectangle(35 + xpos, 650 - ypos, 35 + xpos + Convert.ToSingle(image.Width * 0.5), 650 - ypos + Convert.ToSingle(image.Height * 0.5));
                PdfAnnotation             pdfStamp = PdfAnnotation.CreateStamp(pdfStamper.Writer, rect, null, Guid.NewGuid().ToString());
                image.SetAbsolutePosition(0, 0);
                PdfAppearance app = pdfStamper.GetOverContent(1).CreateAppearance(Convert.ToSingle(image.Width * 0.5), Convert.ToSingle(image.Height * 0.5));
                image.ScalePercent(50);
                app.AddImage(image);
                pdfStamp.SetAppearance(PdfName.N, app);
                pdfStamp.SetPage();
                pdfStamp.Flags = PdfAnnotation.FLAGS_PRINT;
                pdfStamper.AddAnnotation(pdfStamp, 1);
            }


            pdfStamper.Close();
            pdfReader.Close();
            File.Replace(newFile, oldFile, @"backup.pdf.bac");

            Console.WriteLine("Pdf modificado con exito, se ha guardado un backup de la versión anterior ");
            //axAcroPDF1.src = "C:\\Users\\Denisse\\Desktop\\prototipos\\prot2_ReconocerTexto\\prot2_ReconocerTexto\\bin\\Debug\\ejemploOK.pdf";
        }
Exemplo n.º 2
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)) {
                    // 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());
            }
        }