Example #1
0
        public virtual void RemoteGoToDestinationTest01()
        {
            String      cmpFile = sourceFolder + "cmp_remoteGoToDestinationTest01.pdf";
            String      outFile = destinationFolder + "remoteGoToDestinationTest01.pdf";
            PdfDocument @out    = new PdfDocument(new PdfWriter(outFile));

            @out.AddNewPage();
            IList <PdfDestination> destinations = new List <PdfDestination>(7);

            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFit(1));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitH(1, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitV(1, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitR(1, 10, 10, 10, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitB(1));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitBH(1, 10));
            destinations.Add(PdfExplicitRemoteGoToDestination.CreateFitBV(1, 10));
            int y = 785;

            foreach (PdfDestination destination in destinations)
            {
                PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, y, 160, 15));
                PdfAction         action           = PdfAction.CreateGoToR(new PdfStringFS("Some fake destination"), destination);
                linkExplicitDest.SetAction(action);
                @out.GetFirstPage().AddAnnotation(linkExplicitDest);
                y -= 20;
            }
            @out.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
Example #2
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();
        }
Example #3
0
        public virtual void CreatePdf(String dest)
        {
            PdfDocument pdf      = new PdfDocument(new PdfWriter(dest));
            Document    document = new Document(pdf);
            Link        link1    = new Link("Strange Case of Dr. Jekyll and Mr. Hyde", PdfAction.CreateGoToR(new FileInfo(C06E04_TOC_GoToNamed
                                                                                                                          .DEST).Name, 1, true));
            Link link2 = new Link("table of contents", PdfAction.CreateGoToR(new FileInfo(C06E04_TOC_GoToNamed.DEST).Name
                                                                             , "toc", false));
            Paragraph p = new Paragraph().Add("Read the amazing horror story ").Add(link1.SetFontColor(ColorConstants.BLUE)).Add
                              (" or, if you're too afraid to start reading the story, read the ").Add(link2.SetFontColor(ColorConstants.BLUE)
                                                                                                      ).Add(".");

            document.Add(p);
            document.Close();
        }
Example #4
0
        public virtual void RemoteGoToRByStringDestinationTest()
        {
            String      cmpFile = sourceFolder + "cmp_remoteGoToRByStringDestinationTest.pdf";
            String      outFile = destinationFolder + "remoteGoToRByStringDestinationTest.pdf";
            PdfDocument @out    = new PdfDocument(new PdfWriter(outFile));

            @out.AddNewPage();
            PdfLinkAnnotation linkExplicitDest = new PdfLinkAnnotation(new Rectangle(35, 785, 160, 15));
            PdfAction         action           = PdfAction.CreateGoToR("Some fake destination", "1");

            linkExplicitDest.SetAction(action);
            @out.GetFirstPage().AddAnnotation(linkExplicitDest);
            @out.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFile, cmpFile, destinationFolder, "diff_"
                                                                             ));
        }
Example #5
0
        // This method creates a pdf file, which will contain a link
        // to the sixth page of another pdf file.
        private static void CreateLinkPdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);

            // Create a link action, which leads to the another pdf file's page.
            // The 1st argument is the relative destination pdf file's path;
            // the 2nd argument is the number of the page (in the destination pdf file),
            // to which the link will lead after a click on it.
            PdfAction action = PdfAction.CreateGoToR(DEST_NAMES[1], 6);
            Paragraph chunk  = new Paragraph(new Link("Link", action));

            doc.Add(chunk);

            doc.Close();
        }
Example #6
0
        public virtual void StructureDestinationWithoutRemoteIdTest()
        {
            String        srcFile    = sourceFolder + "customRolesMappingPdf2.pdf";
            PdfDocument   document   = new PdfDocument(new PdfReader(srcFile), new PdfWriter(new MemoryStream()));
            PdfStructElem imgElement = new PdfStructElem((PdfDictionary)document.GetPdfObject(13));

            try {
                PdfAction.CreateGoToR(new PdfStringFS("Some fake destination"), PdfStructureDestination.CreateFit(imgElement
                                                                                                                  ));
                NUnit.Framework.Assert.Fail("Exception not thrown");
            }
            catch (ArgumentException e) {
                NUnit.Framework.Assert.AreEqual("Structure destinations shall specify structure element ID in remote go-to actions. Structure element that has no ID is specified instead"
                                                , e.Message);
            }
            document.Close();
        }
Example #7
0
        public virtual void RemoteGoToRIllegalDestinationTest()
        {
            String      outFile  = destinationFolder + "remoteGoToDestinationTest01.pdf";
            PdfDocument document = new PdfDocument(new PdfWriter(outFile));

            document.AddNewPage();
            document.AddNewPage();
            try {
                PdfAction.CreateGoToR(new PdfStringFS("Some fake destination"), PdfExplicitDestination.CreateFitB(document
                                                                                                                  .GetPage(1)));
                NUnit.Framework.Assert.Fail("Exception not thrown");
            }
            catch (ArgumentException e) {
                NUnit.Framework.Assert.AreEqual("Explicit destinations shall specify page number in remote go-to actions instead of page dictionary"
                                                , e.Message);
            }
            document.Close();
        }
Example #8
0
        public void multilayoutpdf()
        {
            // string htmltext = "Indented paragraphs demonstrated in the US Constitution In ancient manuscripts, another means to divide sentences into paragraphs was a line break (newline)followed by an initial at the beginning of the next paragraph. An initial is an oversized capital letter, sometimes outdented beyond the margin of the text. This style can be seen, for example, in the original Old English manuscript of Beowulf.Outdenting is still used in English typography, though not commonly.[3] Modern English typography usually indicates a new paragraph by indenting the first line.This style can be seen in the(handwritten) United States Constitution from 1787.For additional ornamentation, a hedera leaf or other symbol can be added to the inter - paragraph whitespace, or put in the indentation space.";
            try
            {
                System.IO.File.Delete(@"E:\\PDF\\Twocolumns10.pdf");
            }
            catch (Exception e) { }



            string arrowfontpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\Arrows.ttf";

            PdfFont arrowfont = PdfFontFactory.CreateFont(arrowfontpath, PdfEncodings.IDENTITY_H, true);

            PdfWriter   pdfwrite = new PdfWriter("E:\\PDF\\Twocolumns11.pdf");
            PdfDocument pdf      = new PdfDocument(pdfwrite);

            Document         document = new Document(pdf);
            int              nPage    = 0;
            PdfPage          page;
            PdfCanvas        pdfCanvas;
            Rectangle        rectangle;
            Canvas           canvas;
            MyCanvasRenderer renderer;
            Paragraph        P;

            page = pdf.AddNewPage();
            nPage++;
            pdfCanvas = new PdfCanvas(page);
            rectangle = new Rectangle(30, 40, 510, 750);
            canvas    = new Canvas(pdfCanvas, pdf, rectangle);



            renderer = new MyCanvasRenderer(canvas);

            canvas.SetRenderer(renderer);



            for (int i = 0; i < 25; i++)
            {
                float rx     = renderer.GetCurrentArea().GetBBox().GetX();
                float ry     = renderer.GetCurrentArea().GetBBox().GetY();
                float height = renderer.GetCurrentArea().GetBBox().GetHeight();
                float width  = renderer.GetCurrentArea().GetBBox().GetHeight();

                P = new Paragraph("welcome");


                Link link = new Link("Click here", PdfAction.CreateGoToR("Hello", "http: // www.tutorialspoint.com/"));
                P.Add("welcome");
                P.Add(link.SetUnderline()).SetFixedPosition(ry, width, height);
                P.Add("welcome");

                canvas.Add(P);

                // document.Add(P);
            }

            //////page = pdf.AddNewPage();

            ////rectangle = new Rectangle(30, 150, 250, 500);
            ////pdfCanvas = new PdfCanvas(page);
            ////canvas = new Canvas(pdfCanvas, pdf, rectangle);
            ////renderer = new MyCanvasRenderer(canvas);
            ////canvas.SetRenderer(renderer);


            ////int nBlock = 2;
            ////int b;

            ////for (int y = 0; y < 10; y++)
            ////{

            ////    // string pp = "1234567890-=asdfghjkl;'zxcvbnm,./";

            ////    string pp = "Hear";



            ////    //string pp = "!@#$%%^&*()_+QWERTYUIOPASDFGHJKLZXCVBNM{}|";

            ////    //string pp = "!@#$%%^&*()_";


            ////    // P = new Paragraph().Add(new Link("Google", PdfAction.CreateGoToR("HELLO", "www.google.com"))).SetFixedPosition(36, 650, 80);

            ////    //float rheight = renderer.GetOccupiedArea().GetBBox().GetHeight();
            ////    //float rwidght = renderer.GetOccupiedArea().GetBBox().GetHeight();
            ////    //float rx = renderer.GetOccupiedArea().GetBBox().GetX();
            ////   // float ry = renderer.GetOccupiedArea().GetBBox().GetY();



            ////    // Table table = new Table(1);
            ////    // table.SetWidth(500);
            ////    // Cell cell = new Cell();
            ////    // Paragraph p = new Paragraph();
            ////    //// Link link = new Link("link to top of next page", null);

            ////    // p.SetAction(null);

            ////    // cell.Add(p);
            ////    // table.AddCell(cell);



            ////    //PdfAction action = PdfAction.CreateURI("http: // www.tutorialspoint.com/");
            ////    //annotation.SetAction(action);

            ////    //Link link = new Link("Click here", annotation);

            ////    // iText.Kernel.Pdf.Navigation.PdfDestination jekyll =PdfExplicitDestination.CreateFitH(1, 416);

            ////    // P = new Paragraph(new Link("here" , jekyll));

            ////    //// P.Add(link.SetUnderline());

            ////    //            String url = String.Format(
            ////    //"http://www.imdb.com/title/tt%s", record.get(0));

            ////    //PdfDestination destination = new PdfDestination();
            ////    // P.SetAction(PdfAction.CreateJavaScript("app.alert('Boo!');"));

            ////    //P = new Paragraph().Add(new Link("Google", PdfAction.CreateGoTo("www.google.com")));

            ////    //P = new Paragraph(new Link("Link", iText.Kernel.Pdf.Action.PdfAction.CreateGoTo("dest2")));



            ////    //Text t = new Text("This certificate is an important document");

            ////    if (renderer.Full)
            ////    {
            ////        if (nBlock == 1)
            ////        {
            ////            rectangle = new Rectangle(30, 30, 250, 750);
            ////            nBlock = 2;
            ////            page = pdf.AddNewPage();
            ////            nPage++;
            ////        }
            ////        else
            ////        {
            ////            if (nPage == 1)
            ////            {
            ////                rectangle = new Rectangle(300, 150, 250, 500);
            ////            }
            ////            else
            ////            {
            ////                rectangle = new Rectangle(300, 30, 250, 750);
            ////            }
            ////            nBlock = 1;
            ////        }

            ////        pdfCanvas = new PdfCanvas(page);
            ////        canvas = new Canvas(pdfCanvas, pdf, rectangle);
            ////        renderer = new MyCanvasRenderer(canvas);
            ////        canvas.SetRenderer(renderer);
            ////       // document.Add(P);
            ////       canvas.Add(P);
            ////        //canvas.Add(newstr);
            ////    }
            ////    else
            ////    {
            ////        //document.Add(P);
            ////        canvas.Add(P);
            ////        // canvas.Add(P);
            ////        //canvas.Add(newstr);
            ////    }



            ////}



            document.Close();
            pdf.Close();
        }