Beispiel #1
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());
            }
        }
        public void ManipulatePdf(String src, String dest)
        {
            PdfReader      reader       = new PdfReader(src);
            PdfStamper     stamper      = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
            Rectangle      linkLocation = new Rectangle(523, 770, 559, 806);
            PdfDestination destination  = new PdfDestination(PdfDestination.FIT);
            PdfAnnotation  link         = PdfAnnotation.CreateLink(stamper.Writer,
                                                                   linkLocation, PdfAnnotation.HIGHLIGHT_INVERT,
                                                                   3, destination);

            stamper.AddAnnotation(link, 1);
            stamper.Close();
        }
Beispiel #3
0
            public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
            {
                PdfWriter writer;

                PdfWriterWeakRef.TryGetTarget(out writer);
                if (writer == null)
                {
                    return;
                }
                var annot = PdfAnnotation.CreateLink(writer, position, PdfAnnotation.HIGHLIGHT_NONE,
                                                     PdfAction.JavaScript(
                                                         $"this.exportDataObject({{ cName: '{AttachmentName}', nLaunch: 2 }});", writer));

                annot.Border = new PdfBorderArray(0, 0, 0);
                writer.AddAnnotation(annot);
            }
Beispiel #4
0
        public void AddNavigationTest()
        {
            String         src     = srcFolder + "primes.pdf";
            String         dest    = outFolder + "primes_links.pdf";
            PdfReader      reader  = new PdfReader(src);
            PdfStamper     stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create));
            PdfDestination d       = new PdfDestination(PdfDestination.FIT);
            Rectangle      rect    = new Rectangle(0, 806, 595, 842);
            PdfAnnotation  a10     = PdfAnnotation.CreateLink(stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_INVERT, 2, d);

            stamper.AddAnnotation(a10, 1);
            PdfAnnotation a1 = PdfAnnotation.CreateLink(stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_PUSH, 1, d);

            stamper.AddAnnotation(a1, 2);
            stamper.Close();
            CompareTool compareTool  = new CompareTool();
            String      errorMessage = compareTool.CompareByContent(dest, srcFolder + "cmp_primes_links.pdf", outFolder, "diff_");

            if (errorMessage != null)
            {
                Assert.Fail(errorMessage);
            }
        }