Exemplo n.º 1
0
 public void DrawLine(Pen2 pen, float x1, float y1, float x2, float y2)
 {
     SetPen(pen);
     template.MoveTo(x1, currentHeight - y1);
     template.LineTo(x2, currentHeight - y2);
     template.Stroke();
 }
        // Private Methods

        private void addMarkerLineToChart(float y1)
        {
            _template.SetLineWidth(HorizontalLineWidth);
            _template.SetColorStroke(HorizontalGridColor);
            _template.MoveTo(Margin + _leftMargin, y1);
            _template.LineTo(Margin + _leftMargin - 4, y1);
            _template.Stroke();
        }
Exemplo n.º 3
0
        // Private Methods

        private void addMarkerLineToChart(float x1)
        {
            _template.SetLineWidth(HorizontalLineWidth);
            _template.SetColorStroke(HorizontalGridColor);
            _template.MoveTo(x1, Margin + _bottomMargin);
            _template.LineTo(x1, Margin + _bottomMargin - 4);
            _template.Stroke();
        }
Exemplo n.º 4
0
        private void drawSegment(PieChartSegment segment)
        {
            var x1OnCircle = (float)(_circleCenterX0 + Radius * Math.Cos(_startAngle * Math.PI / 180));
            var y1OnCircle = (float)(_circleCenterY0 + Radius * Math.Sin(_startAngle * Math.PI / 180));

            _endAngle += segment.Percentage <= 50 ? segment.Angle : 180;
            var x2 = (float)(_circleCenterX0 + Radius * Math.Cos(_endAngle * Math.PI / 180));
            var y2 = (float)(_circleCenterY0 + Radius * Math.Sin(_endAngle * Math.PI / 180));

            //draw the triangle within the circle
            _template.SetColorStroke(segment.Color);
            _template.SetColorFill(segment.Color);
            _template.MoveTo(_circleCenterX0, _circleCenterY0);
            _template.LineTo(x1OnCircle, y1OnCircle);
            _template.LineTo(x2, y2);
            _template.LineTo(_circleCenterX0, _circleCenterY0);
            _template.FillStroke();

            //draw the arc
            _template.Arc(
                _circleCenterX0 - Radius,
                _circleCenterY0 - Radius,
                _circleCenterX0 + Radius,
                _circleCenterY0 + Radius,
                _startAngle,
                segment.Percentage <= 50 ? segment.Angle : 180);
            _template.FillStroke();
        }
Exemplo n.º 5
0
        public PdfTemplate AddPageFooter(int PageNumber)
        {
            PdfTemplate footerTemplate = cb.CreateTemplate(500, 55);

            footerTemplate.BeginText();
            BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ITALIC, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);

            footerTemplate.SetFontAndSize(bf2, 11);
            footerTemplate.SetColorStroke(BaseColor.DARK_GRAY);
            footerTemplate.SetColorFill(BaseColor.GRAY);
            int al = -200;

            footerTemplate.SetLineWidth(3);
            footerTemplate.LineTo(500, footerTemplate.YTLM);
            string texttoadd   = "Page: " + PageNumber.ToString();
            float  widthoftext = 500.0f - bf2.GetWidthPoint(texttoadd, 11);

            footerTemplate.ShowTextAligned(al, texttoadd, widthoftext, 30, 0);
            footerTemplate.EndText();
            return(footerTemplate);
        }
Exemplo n.º 6
0
        public Chap1008()
        {
            Console.WriteLine("Chapter 10 example 8: Irregular columns");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2: creation of the writer
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1008.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4:
                BaseFont bf   = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                Font     font = new Font(bf, 11, Font.NORMAL);

                // we grab the contentbyte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                PdfTemplate t      = cb.CreateTemplate(600, 800);
                Image       caesar = Image.GetInstance("caesar_coin.jpg");
                cb.AddImage(caesar, 100, 0, 0, 100, 260, 595);
                t.SetGrayFill(0.75f);
                t.MoveTo(310, 112);
                t.LineTo(280, 60);
                t.LineTo(340, 60);
                t.ClosePath();
                t.MoveTo(310, 790);
                t.LineTo(310, 710);
                t.MoveTo(310, 580);
                t.LineTo(310, 122);
                t.Stroke();
                cb.AddTemplate(t, 0, 0);

                ColumnText ct = new ColumnText(cb);
                ct.AddText(new Phrase("GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n", FontFactory.GetFont(FontFactory.HELVETICA, 12)));
                ct.AddText(new Phrase("Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", FontFactory.GetFont(FontFactory.HELVETICA, 12)));

                float[] left1  = { 70, 790, 70, 60 };
                float[] right1 = { 300, 790, 300, 700, 240, 700, 240, 590, 300, 590, 300, 106, 270, 60 };
                float[] left2  = { 320, 790, 320, 700, 380, 700, 380, 590, 320, 590, 320, 106, 350, 60 };
                float[] right2 = { 550, 790, 550, 60 };

                int status = 0;
                int column = 0;
                while ((status & ColumnText.NO_MORE_TEXT) == 0)
                {
                    if (column == 0)
                    {
                        ct.SetColumns(left1, right1);
                        column = 1;
                    }
                    else
                    {
                        ct.SetColumns(left2, right2);
                        column = 0;
                    }
                    status       = ct.Go();
                    ct.YLine     = 790;
                    ct.Alignment = Element.ALIGN_JUSTIFIED;
                    status       = ct.Go();
                    if ((column == 0) && ((status & ColumnText.NO_MORE_COLUMN) != 0))
                    {
                        document.NewPage();
                        cb.AddTemplate(t, 0, 0);
                        cb.AddImage(caesar, 100, 0, 0, 100, 260, 595);
                    }
                }

                // step 5: we close the document
                document.Close();
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }
        }
Exemplo n.º 7
0
        public Chap1013()
        {
            Console.WriteLine("Chapter 10 Example 13: Spot Color");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1013.pdf", FileMode.Create));
                BaseFont  bf     = BaseFont.CreateFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED);

                // step 3: we open the document
                document.Open();

                // step 4: we add some content
                PdfContentByte cb = writer.DirectContent;

                // Note: I made up these names unless someone give me a PANTONE swatch as gift ([email protected])
                PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", 0.25f, new CMYKColor(0.9f, .2f, .3f, .1f));
                PdfSpotColor spc_rgb  = new PdfSpotColor("PANTONE 147", 0.9f, new Color(114, 94, 38));
                PdfSpotColor spc_g    = new PdfSpotColor("PANTONE 100 CV", 0.5f, new GrayColor(0.9f));

                // Stroke a rectangle with CMYK alternate
                cb.SetColorStroke(spc_cmyk, .5f);
                cb.SetLineWidth(10f);
                // draw a rectangle
                cb.Rectangle(100, 700, 100, 100);
                // add the diagonal
                cb.MoveTo(100, 700);
                cb.LineTo(200, 800);
                // stroke the lines
                cb.Stroke();

                // Fill a rectangle with CMYK alternate
                cb.SetColorFill(spc_cmyk, spc_cmyk.Tint);
                cb.Rectangle(250, 700, 100, 100);
                cb.Fill();

                // Stroke a circle with RGB alternate
                cb.SetColorStroke(spc_rgb, spc_rgb.Tint);
                cb.SetLineWidth(5f);
                cb.Circle(150f, 500f, 100f);
                cb.Stroke();

                // Fill the circle with RGB alternate
                cb.SetColorFill(spc_rgb, spc_rgb.Tint);
                cb.Circle(150f, 500f, 50f);
                cb.Fill();

                // example with colorfill
                cb.SetColorFill(spc_g, spc_g.Tint);
                cb.MoveTo(100f, 200f);
                cb.LineTo(200f, 250f);
                cb.LineTo(400f, 150f);
                cb.Fill();
                document.NewPage();
                String text = "Some text to show";
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk))));
                document.Add(new Paragraph(text, FontFactory.GetFont(FontFactory.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.5f))));

                // example with template
                PdfTemplate t = cb.CreateTemplate(500f, 500f);
                // Stroke a rectangle with CMYK alternate
                t.SetColorStroke(new SpotColor(spc_cmyk, .5f));
                t.SetLineWidth(10f);
                // draw a rectangle
                t.Rectangle(100, 10, 100, 100);
                // add the diagonal
                t.MoveTo(100, 10);
                t.LineTo(200, 100);
                // stroke the lines
                t.Stroke();

                // Fill a rectangle with CMYK alternate
                t.SetColorFill(spc_g, spc_g.Tint);
                t.Rectangle(100, 125, 100, 100);
                t.Fill();
                t.BeginText();
                t.SetFontAndSize(bf, 20f);
                t.SetTextMatrix(1f, 0f, 0f, 1f, 10f, 10f);
                t.ShowText("Template text upside down");
                t.EndText();
                t.Rectangle(0, 0, 499, 499);
                t.Stroke();
                cb.AddTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f);
            }
            catch (Exception de)
            {
                Console.Error.WriteLine(de.Message);
                Console.Error.WriteLine(de.StackTrace);
            }

            // step 5: we close the document
            document.Close();
        }
Exemplo n.º 8
0
        public Chap1003()
        {
            Console.WriteLine("Chapter 10 example 3: Templates");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1003.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4: we grab the ContentByte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                // we create a PdfTemplate
                PdfTemplate template = cb.CreateTemplate(500, 200);

                // we add some graphics
                template.MoveTo(0, 200);
                template.LineTo(500, 0);
                template.Stroke();
                template.SetRGBColorStrokeF(255f, 0f, 0f);
                template.Circle(250f, 100f, 80f);
                template.Stroke();

                // we add some text
                template.BeginText();
                BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                template.SetFontAndSize(bf, 12);
                template.SetTextMatrix(100, 100);
                template.ShowText("Text at the position 100,100 (relative to the template!)");
                template.EndText();

                // we add the template on different positions
                cb.AddTemplate(template, 0, 0);
                cb.AddTemplate(template, 0, 1, -1, 0, 500, 200);
                cb.AddTemplate(template, .5f, 0, 0, .5f, 100, 400);

                // we go to a new page
                document.NewPage();
                cb.AddTemplate(template, 0, 400);
                cb.AddTemplate(template, 2, 0, 0, 2, -200, 400);
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }
Exemplo n.º 9
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                PdfContentByte canvas = writer.DirectContent;
                // line widths
                canvas.SaveState();
                for (int i = 25; i > 0; i--)
                {
                    canvas.SetLineWidth((float)i / 10);
                    canvas.MoveTo(50, 806 - (5 * i));
                    canvas.LineTo(320, 806 - (5 * i));
                    canvas.Stroke();
                }
                canvas.RestoreState();

                // line cap
                canvas.MoveTo(350, 800);
                canvas.LineTo(350, 750);
                canvas.MoveTo(540, 800);
                canvas.LineTo(540, 750);
                canvas.Stroke();

                canvas.SaveState();
                canvas.SetLineWidth(8);
                canvas.SetLineCap(PdfContentByte.LINE_CAP_BUTT);
                canvas.MoveTo(350, 790);
                canvas.LineTo(540, 790);
                canvas.Stroke();
                canvas.SetLineCap(PdfContentByte.LINE_CAP_ROUND);
                canvas.MoveTo(350, 775);
                canvas.LineTo(540, 775);
                canvas.Stroke();
                canvas.SetLineCap(PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
                canvas.MoveTo(350, 760);
                canvas.LineTo(540, 760);
                canvas.Stroke();
                canvas.RestoreState();

                // join miter
                canvas.SaveState();
                canvas.SetLineWidth(8);
                canvas.SetLineJoin(PdfContentByte.LINE_JOIN_MITER);
                canvas.MoveTo(387, 700);
                canvas.LineTo(402, 730);
                canvas.LineTo(417, 700);
                canvas.Stroke();
                canvas.SetLineJoin(PdfContentByte.LINE_JOIN_ROUND);
                canvas.MoveTo(427, 700);
                canvas.LineTo(442, 730);
                canvas.LineTo(457, 700);
                canvas.Stroke();
                canvas.SetLineJoin(PdfContentByte.LINE_JOIN_BEVEL);
                canvas.MoveTo(467, 700);
                canvas.LineTo(482, 730);
                canvas.LineTo(497, 700);
                canvas.Stroke();
                canvas.RestoreState();

                // line dash
                canvas.SaveState();
                canvas.SetLineWidth(3);
                canvas.MoveTo(50, 660);
                canvas.LineTo(320, 660);
                canvas.Stroke();
                canvas.SetLineDash(6, 0);
                canvas.MoveTo(50, 650);
                canvas.LineTo(320, 650);
                canvas.Stroke();
                canvas.SetLineDash(6, 3);
                canvas.MoveTo(50, 640);
                canvas.LineTo(320, 640);
                canvas.Stroke();
                canvas.SetLineDash(15, 10, 5);
                canvas.MoveTo(50, 630);
                canvas.LineTo(320, 630);
                canvas.Stroke();
                float[] dash1 = { 10, 5, 5, 5, 20 };
                canvas.SetLineDash(dash1, 5);
                canvas.MoveTo(50, 620);
                canvas.LineTo(320, 620);
                canvas.Stroke();
                float[] dash2 = { 9, 6, 0, 6 };
                canvas.SetLineCap(PdfContentByte.LINE_CAP_ROUND);
                canvas.SetLineDash(dash2, 0);
                canvas.MoveTo(50, 610);
                canvas.LineTo(320, 610);
                canvas.Stroke();
                canvas.RestoreState();

                // miter limit
                PdfTemplate hooks = canvas.CreateTemplate(300, 120);
                hooks.SetLineWidth(8);
                hooks.MoveTo(46, 50);
                hooks.LineTo(65, 80);
                hooks.LineTo(84, 50);
                hooks.Stroke();
                hooks.MoveTo(87, 50);
                hooks.LineTo(105, 80);
                hooks.LineTo(123, 50);
                hooks.Stroke();
                hooks.MoveTo(128, 50);
                hooks.LineTo(145, 80);
                hooks.LineTo(162, 50);
                hooks.Stroke();
                hooks.MoveTo(169, 50);
                hooks.LineTo(185, 80);
                hooks.LineTo(201, 50);
                hooks.Stroke();
                hooks.MoveTo(210, 50);
                hooks.LineTo(225, 80);
                hooks.LineTo(240, 50);
                hooks.Stroke();

                canvas.SaveState();
                canvas.SetMiterLimit(2);
                canvas.AddTemplate(hooks, 300, 600);
                canvas.RestoreState();

                canvas.SaveState();
                canvas.SetMiterLimit(2.1f);
                canvas.AddTemplate(hooks, 300, 550);
                canvas.RestoreState();
            }
        }
Exemplo n.º 10
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                PdfContentByte canvas = writer.DirectContent;
                String         text   = "AWAY again";
                BaseFont       bf     = BaseFont.CreateFont();
                canvas.BeginText();
                // line 1
                canvas.SetFontAndSize(bf, 16);
                canvas.MoveText(36, 806);
                canvas.MoveTextWithLeading(0, -24);
                canvas.ShowText(text);
                // line 2
                canvas.SetWordSpacing(20);
                canvas.NewlineShowText(text);
                // line 3
                canvas.SetCharacterSpacing(10);
                canvas.NewlineShowText(text);
                canvas.SetWordSpacing(0);
                canvas.SetCharacterSpacing(0);
                // line 4
                canvas.SetHorizontalScaling(50);
                canvas.NewlineShowText(text);
                canvas.SetHorizontalScaling(100);
                // line 5
                canvas.NewlineShowText(text);
                canvas.SetTextRise(15);
                canvas.SetFontAndSize(bf, 12);
                canvas.SetColorFill(BaseColor.RED);
                canvas.ShowText("2");
                canvas.SetColorFill(GrayColor.GRAYBLACK);
                // line 6
                canvas.SetLeading(56);
                canvas.NewlineShowText("Changing the leading: " + text);
                canvas.SetLeading(24);
                canvas.NewlineText();
                // line 7
                PdfTextArray array = new PdfTextArray("A");
                array.Add(120);
                array.Add("W");
                array.Add(120);
                array.Add("A");
                array.Add(95);
                array.Add("Y again");
                canvas.ShowText(array);
                canvas.EndText();

                canvas.SetColorFill(BaseColor.BLUE);
                canvas.BeginText();
                canvas.SetTextMatrix(360, 770);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();

                canvas.BeginText();
                canvas.SetTextMatrix(360, 730);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();

                canvas.BeginText();
                canvas.SetTextMatrix(360, 690);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();

                canvas.BeginText();
                canvas.SetTextMatrix(360, 650);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();

                PdfTemplate template = canvas.CreateTemplate(200, 36);
                template.SetLineWidth(2);
                for (int i = 0; i < 6; i++)
                {
                    template.MoveTo(0, i * 6);
                    template.LineTo(200, i * 6);
                }
                template.Stroke();

                canvas.SaveState();
                canvas.BeginText();
                canvas.SetTextMatrix(360, 610);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_CLIP);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();
                canvas.AddTemplate(template, 360, 610);
                canvas.RestoreState();

                canvas.SaveState();
                canvas.BeginText();
                canvas.SetTextMatrix(360, 570);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE_CLIP);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();
                canvas.AddTemplate(template, 360, 570);
                canvas.RestoreState();

                canvas.SaveState();
                canvas.BeginText();
                canvas.SetTextMatrix(360, 530);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE_CLIP);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();
                canvas.AddTemplate(template, 360, 530);
                canvas.RestoreState();

                canvas.SaveState();
                canvas.BeginText();
                canvas.SetTextMatrix(360, 490);
                canvas.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_CLIP);
                canvas.SetFontAndSize(bf, 24);
                canvas.ShowText(text);
                canvas.EndText();
                canvas.AddTemplate(template, 360, 490);
                canvas.RestoreState();
            }
        }
Exemplo n.º 11
0
        public Chap1107()
        {
            Console.WriteLine("Chapter 11 example 7: Outlines and Destinations");

            // step 1: creation of a document-object
            Document document = new Document();

            try
            {
                // step 2:
                // we create a writer that listens to the document
                // and directs a PDF-stream to a file
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1107.pdf", FileMode.Create));

                // step 3: we open the document
                document.Open();

                // step 4: we grab the ContentByte and do some stuff with it
                PdfContentByte cb = writer.DirectContent;

                // we create a PdfTemplate
                PdfTemplate template = cb.CreateTemplate(25, 25);

                // we add some crosses to visualize the destinations
                template.MoveTo(13, 0);
                template.LineTo(13, 25);
                template.MoveTo(0, 13);
                template.LineTo(50, 13);
                template.Stroke();

                // we add the template on different positions
                cb.AddTemplate(template, 287, 787);
                cb.AddTemplate(template, 187, 487);
                cb.AddTemplate(template, 487, 287);
                cb.AddTemplate(template, 87, 87);

                // we define the destinations
                PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
                PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
                PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
                PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
                PdfDestination d5 = new PdfDestination(PdfDestination.FIT);

                // we define the outlines
                PdfOutline out1 = new PdfOutline(cb.RootOutline, d1, "root");
                PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
                PdfOutline out3 = new PdfOutline(out1, d3, "sub 2");
                PdfOutline out4 = new PdfOutline(out2, d4, "sub 2.1");
                PdfOutline out5 = new PdfOutline(out2, d5, "sub 2.2");

                cb.AddOutline(out1);
                cb.AddOutline(out2);
                cb.AddOutline(out3);
                cb.AddOutline(out4);
                cb.AddOutline(out5);
            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();
        }