public virtual void CreatePdf(String dest)
        {
            //Initialize PDF document
            PdfDocument pdf       = new PdfDocument(new PdfWriter(dest));
            PdfPage     page      = pdf.AddNewPage();
            PdfCanvas   pdfCanvas = new PdfCanvas(page);
            Rectangle   rectangle = new Rectangle(36, 500, 100, 250);

            pdfCanvas.Rectangle(rectangle);
            pdfCanvas.Stroke();
            iText.Layout.Canvas canvas   = new iText.Layout.Canvas(pdfCanvas, rectangle);
            MyCanvasRenderer    renderer = new MyCanvasRenderer(canvas);

            canvas.SetRenderer(renderer);
            PdfFont   font   = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont   bold   = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);
            Text      title  = new Text("The Strange Case of Dr. Jekyll and Mr. Hyde").SetFont(bold);
            Text      author = new Text("Robert Louis Stevenson").SetFont(font);
            Paragraph p      = new Paragraph().Add(title).Add(" by ").Add(author);

            while (!renderer.IsFull())
            {
                canvas.Add(p);
            }
            //Close document
            pdf.Close();
        }
Beispiel #2
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();
        }