// ---------------------------------------------------------------------------

        /**
         * Manipulates a PDF file src with the file dest as result (localhost)
         * @param src the original PDF
         */
        public byte[] ManipulatePdf(byte[] src)
        {
            // Create the reader
            PdfReader reader = new PdfReader(src);
            int       n      = reader.NumberOfPages;

            using (MemoryStream ms = new MemoryStream())
            {
                // Create the stamper
                using (PdfStamper stamper = new PdfStamper(reader, ms))
                {
                    // Add JavaScript
                    jsString = File.ReadAllText(
                        Path.Combine(Utility.ResourceJavaScript, RESOURCE)
                        );
                    stamper.JavaScript = jsString;
                    // Create a Chunk with a chained action
                    PdfContentByte canvas;
                    Chunk          chunk  = new Chunk("print this page");
                    PdfAction      action = PdfAction.JavaScript(
                        "app.alert('Think before you print!');",
                        stamper.Writer
                        );
                    action.Next(PdfAction.JavaScript(
                                    "printCurrentPage(this.pageNum);",
                                    stamper.Writer
                                    ));
                    action.Next(new PdfAction("http://www.panda.org/savepaper/"));
                    chunk.SetAction(action);
                    Phrase phrase = new Phrase(chunk);
                    // Add this Chunk to every page
                    for (int i = 0; i < n;)
                    {
                        canvas = stamper.GetOverContent(++i);
                        ColumnText.ShowTextAligned(
                            canvas, Element.ALIGN_RIGHT, phrase, 816, 18, 0
                            );
                    }
                }
                return(ms.ToArray());
            }
        }
Example #2
0
        public virtual void SoundAndTwoNextJavaScriptActionTest()
        {
            String      fileName = "soundAndTwoNextJavaScriptActionTest.pdf";
            PdfDocument document = CreateDocument(new PdfWriter(destinationFolder + fileName), false);
            Stream      @is      = new FileStream(sourceFolder + "sample.aif", FileMode.Open, FileAccess.Read);
            PdfStream   sound1   = new PdfStream(document, @is);

            sound1.Put(PdfName.R, new PdfNumber(32117));
            sound1.Put(PdfName.E, PdfName.Signed);
            sound1.Put(PdfName.B, new PdfNumber(16));
            sound1.Put(PdfName.C, new PdfNumber(1));
            PdfAction action = PdfAction.CreateSound(sound1);

            action.Next(PdfAction.CreateJavaScript("this.setPageRotations(0,2,90)"));
            action.Next(PdfAction.CreateJavaScript("this.setPageRotations(0,2,180)"));
            document.GetPage(2).SetAdditionalAction(PdfName.O, action);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + fileName, sourceFolder
                                                                             + "cmp_" + fileName, destinationFolder, "diff_"));
        }
Example #3
0
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf);
            PdfAction   action   = PdfAction.CreateJavaScript("app.alert('Boo');");

            action.Next(PdfAction.CreateGoToR(new FileInfo(C06E04_TOC_GoToNamed.DEST).Name, 1, true));
            Link      link = new Link("here", action);
            Paragraph p    = new Paragraph().Add("Click ").Add(link.SetFontColor(ColorConstants.BLUE)).Add(" if you want to be scared."
                                                                                                           );

            document.Add(p);
            document.Close();
        }