Esempio n. 1
0
            public override void Draw(DrawContext drawContext)
            {
                for (int i = 0; i < rows.Count && null != rows[i] && null != rows[i][0]; i++)
                {
                    CellRenderer[] renderers = rows[i];
                    Rectangle      leftCell  = renderers[0].GetOccupiedAreaBBox();
                    Rectangle      rightCell = renderers[renderers.Length - 1].GetOccupiedAreaBBox();
                    Rectangle      rect      = new Rectangle(leftCell.GetLeft(), leftCell.GetBottom(),
                                                             rightCell.GetRight() - leftCell.GetLeft
                                                                 (), leftCell.GetHeight());
                    PdfCanvas canvas = drawContext.GetCanvas();
                    canvas.SaveState();
                    if (isOdd)
                    {
                        canvas.SetFillColor(ColorConstants.LIGHT_GRAY);
                        isOdd = false;
                    }
                    else
                    {
                        canvas.SetFillColor(ColorConstants.YELLOW);
                        isOdd = true;
                    }

                    canvas.Rectangle(rect);
                    canvas.Fill();
                    canvas.RestoreState();
                }

                base.Draw(drawContext);
            }
Esempio n. 2
0
        /* (non-Javadoc)
         * @see com.itextpdf.layout.renderer.AbstractRenderer#drawChildren(com.itextpdf.layout.renderer.DrawContext)
         */
        public override void DrawChildren(DrawContext drawContext)
        {
            drawContext.GetCanvas().SaveState();
            bool flatten = IsFlatten();

            if (flatten)
            {
                drawContext.GetCanvas().Rectangle(ApplyBorderBox(occupiedArea.GetBBox(), false)).Clip().NewPath();
                flatRenderer.Draw(drawContext);
            }
            else
            {
                ApplyAcroField(drawContext);
            }
            drawContext.GetCanvas().RestoreState();
        }
Esempio n. 3
0
        public override void Draw(DrawContext drawContext)
        {
            // Fictitiously layout the renderer and find out, how much space does it require
            IRenderer pr = content.CreateRendererSubTree().SetParent(this);

            LayoutResult textArea = pr.Layout(new LayoutContext(
                                                  new LayoutArea(0, new Rectangle(GetOccupiedAreaBBox().GetWidth(), 1000))));

            float spaceNeeded = textArea.GetOccupiedArea().GetBBox().GetHeight();

            Console.WriteLine("The content requires {0} pt whereas the height is {1} pt.",
                              spaceNeeded, GetOccupiedAreaBBox().GetHeight());

            float offset = (GetOccupiedAreaBBox().GetHeight() - textArea.GetOccupiedArea()
                            .GetBBox().GetHeight()) / 2;

            Console.WriteLine("The difference is {0} pt; we'll need an offset of {1} pt.",
                              -2f * offset, offset);

            PdfFormXObject xObject = new PdfFormXObject(new Rectangle(GetOccupiedAreaBBox().GetWidth(),
                                                                      GetOccupiedAreaBBox().GetHeight()));

            Canvas layoutCanvas = new Canvas(new PdfCanvas(xObject, drawContext.GetDocument()),
                                             drawContext.GetDocument(),
                                             new Rectangle(0, offset, GetOccupiedAreaBBox().GetWidth(), spaceNeeded));

            layoutCanvas.Add(content);

            drawContext.GetCanvas().AddXObject(xObject, occupiedArea.GetBBox().GetLeft(),
                                               occupiedArea.GetBBox().GetBottom());
        }
Esempio n. 4
0
            public override void DrawChildren(DrawContext drawContext)
            {
                // Use the coordinates of the cell in the fourth row and the second column to draw the image
                Rectangle rect = rows[3][1].GetOccupiedAreaBBox();

                base.DrawChildren(drawContext);

                drawContext.GetCanvas().AddImageAt(image, rect.GetLeft() + 10, rect.GetTop() - image.GetHeight(), false);
            }
Esempio n. 5
0
            protected override void DrawBorders(DrawContext drawContext)
            {
                Rectangle rect = GetOccupiedAreaBBox();

                drawContext.GetCanvas()
                .SaveState()
                .Rectangle(rect.GetLeft(), rect.GetBottom(), rect.GetWidth(), rect.GetHeight())
                .Stroke()
                .RestoreState();
            }
Esempio n. 6
0
            protected override void DrawBorders(DrawContext drawContext)
            {
                Rectangle occupiedAreaBBox = this.GetOccupiedAreaBBox();

                UnitValue[] margins   = this.GetMargins();
                Rectangle   rectangle = this.ApplyMargins(occupiedAreaBBox, margins, false);
                PdfCanvas   canvas    = drawContext.GetCanvas();

                canvas.RoundRectangle(rectangle.GetX() + 1, rectangle.GetY() + 1, rectangle.GetWidth() - 2, rectangle.GetHeight
                                          () - 2, 5).Stroke();
                base.DrawBorder(drawContext);
            }
Esempio n. 7
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfCanvas canvas = drawContext.GetCanvas();
                Rectangle bbox   = GetOccupiedArea().GetBBox();

                canvas.SetLineDash(3f, 3f);
                canvas.MoveTo(bbox.GetLeft(), bbox.GetBottom());
                canvas.LineTo(bbox.GetRight(), bbox.GetBottom());
                canvas.MoveTo(bbox.GetLeft(), bbox.GetTop());
                canvas.LineTo(bbox.GetRight(), bbox.GetTop());
                canvas.Stroke();
            }
Esempio n. 8
0
            public override void DrawChildren(DrawContext drawContext)
            {
                base.DrawChildren(drawContext);
                PdfCanvas canvas      = drawContext.GetCanvas();
                Rectangle headersArea = headerRenderer.GetOccupiedArea().GetBBox();

                canvas.SetLineDash(3f, 3f);
                canvas.MoveTo(headersArea.GetLeft(), headersArea.GetTop());
                canvas.LineTo(headersArea.GetRight(), headersArea.GetTop());
                canvas.MoveTo(headersArea.GetLeft(), headersArea.GetBottom());
                canvas.LineTo(headersArea.GetRight(), headersArea.GetBottom());
                canvas.Stroke();
            }
 public override void DrawChildren(DrawContext drawContext)
 {
     if (this._enclosing.IsBoxChecked())
     {
         PdfCanvas canvas    = drawContext.GetCanvas();
         Rectangle rectangle = this.GetInnerAreaBBox();
         canvas.SaveState();
         canvas.SetFillColor(ColorConstants.BLACK);
         DrawingUtil.DrawPdfACheck(canvas, rectangle.GetWidth(), rectangle.GetHeight(), rectangle.GetLeft(), rectangle
                                   .GetBottom());
         canvas.RestoreState();
     }
 }
Esempio n. 10
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                Paragraph p      = new Paragraph(content).SetFontColor(ColorConstants.WHITE);
                Rectangle rect   = GetOccupiedAreaBBox();
                float     coordX = (rect.GetLeft() + rect.GetRight()) / 2;
                float     coordY = (rect.GetBottom() + rect.GetTop()) / 2;
                float     angle  = (float)Math.PI / 6;

                new Canvas(drawContext.GetCanvas(), rect)
                .ShowTextAligned(p, coordX, coordY, GetOccupiedArea().GetPageNumber(),
                                 TextAlignment.CENTER, VerticalAlignment.MIDDLE, angle)
                .Close();
            }
Esempio n. 11
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                Rectangle rect   = this.GetOccupiedAreaBBox();
                PdfCanvas canvas = drawContext.GetCanvas();

                canvas
                .SaveState()
                .SetLineDash(3, 3)
                .MoveTo(rect.GetLeft(), rect.GetBottom() - 3)
                .LineTo(rect.GetRight(), rect.GetBottom() - 3)
                .Stroke()
                .RestoreState();
            }
Esempio n. 12
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                int       pageNumber = GetOccupiedArea().GetPageNumber();
                Rectangle rect       = GetOccupiedAreaBBox();

                Paragraph p      = new Paragraph(footer.AddRow(pageNumber).ToString());
                float     coordX = (rect.GetLeft() + rect.GetRight()) / 2;
                float     coordY = (rect.GetBottom() + rect.GetTop()) / 2;
                Canvas    canvas = new Canvas(drawContext.GetCanvas(), rect);

                canvas
                .ShowTextAligned(p, coordX, coordY, TextAlignment.CENTER, VerticalAlignment.MIDDLE)
                .Close();
            }
Esempio n. 13
0
            public override void DrawChildren(DrawContext drawContext)
            {
                PdfCanvas canvas    = drawContext.GetCanvas();
                Rectangle rectangle = this._enclosing.flatRenderer.GetOccupiedArea().GetBBox();
                float     radius    = (float)Math.Min(rectangle.GetWidth(), rectangle.GetHeight()) / 2;

                canvas.SaveState();
                canvas.SetFillColor(RadioRenderer.DEFAULT_COLOR);
                DrawingUtil.DrawCircle(canvas, rectangle.GetLeft() + radius, rectangle.GetBottom() + radius, radius);
                if (this._enclosing.IsBoxChecked())
                {
                    canvas.SetFillColor(RadioRenderer.DEFAULT_CHECKED_COLOR);
                    DrawingUtil.DrawCircle(canvas, rectangle.GetLeft() + radius, rectangle.GetBottom() + radius, radius / 2);
                }
                canvas.RestoreState();
            }
            public override void DrawBorder(DrawContext drawContext)
            {
                Rectangle rectangle = this.GetOccupiedAreaBBox();
                float     llx       = rectangle.GetX() + 1;
                float     lly       = rectangle.GetY() + 1;
                float     urx       = rectangle.GetX() + this.GetOccupiedAreaBBox().GetWidth() - 1;
                float     ury       = rectangle.GetY() + this.GetOccupiedAreaBBox().GetHeight() - 1;
                PdfCanvas canvas    = drawContext.GetCanvas();
                float     r         = 4;
                float     b         = 0.4477f;

                canvas.MoveTo(llx, lly).LineTo(urx, lly).LineTo(urx, ury - r).CurveTo(urx, ury - r * b, urx - r * b, ury,
                                                                                      urx - r, ury).LineTo(llx + r, ury).CurveTo(llx + r * b, ury, llx, ury - r * b, llx, ury - r).LineTo(llx
                                                                                                                                                                                          , lly).Stroke();
                base.DrawBorder(drawContext);
            }
Esempio n. 15
0
            public override void DrawBorder(DrawContext drawContext)
            {
                PdfCanvas canvas = drawContext.GetCanvas();
                Rectangle rect   = GetOccupiedAreaBBox();

                canvas
                .SaveState()
                .MoveTo(rect.GetLeft(), rect.GetTop())
                .LineTo(rect.GetRight(), rect.GetBottom())
                .Stroke()
                .RestoreState();

                new Canvas(canvas, GetOccupiedAreaBBox())
                .ShowTextAligned(textTopRight, rect.GetRight() - 2, rect.GetTop() - 2,
                                 TextAlignment.RIGHT, VerticalAlignment.TOP, 0)
                .ShowTextAligned(textBottomLeft, rect.GetLeft() + 2, rect.GetBottom() + 2, TextAlignment.LEFT);
            }
    public override void DrawBackground(DrawContext drawContext)
    {
        // Apply the margins
        var area = ApplyMargins(GetOccupiedAreaBBox(), GetMargins(), false);

        // Get background color
        var background = GetProperty <Background>(Property.BACKGROUND);
        var color      = background.GetColor();

        // Draw the rectangle with rounded corners
        var canvas = drawContext.GetCanvas();

        canvas.SaveState();
        canvas.RoundRectangle(area.GetX(), area.GetY(), area.GetWidth(), area.GetHeight(), 5);
        canvas.SetFillColor(color);
        canvas.Fill();
        canvas.RestoreState();
    }
Esempio n. 17
0
            public override void DrawChildren(DrawContext drawContext)
            {
                base.DrawChildren(drawContext);

                foreach (IRenderer renderer in childRenderers)
                {
                    PdfCanvas canvas = drawContext.GetCanvas();
                    canvas.BeginText();
                    Rectangle box      = ((AbstractRenderer)renderer).GetInnerAreaBBox();
                    UnitValue fontSize = GetPropertyAsUnitValue(Property.FONT_SIZE);
                    canvas.MoveText(box.GetLeft(),
                                    box.GetTop() - (fontSize.IsPointValue() ? fontSize.GetValue() : 12f));
                    canvas.SetFontAndSize(GetPropertyAsFont(Property.FONT),
                                          fontSize.IsPointValue() ? fontSize.GetValue() : 12f);
                    canvas.ShowText("This inner table header will always be repeated");
                    canvas.EndText();
                    canvas.Stroke();
                }
            }
Esempio n. 18
0
            public override void Draw(DrawContext drawContext)
            {
                PdfCanvas canvas   = drawContext.GetCanvas();
                Rectangle position = GetOccupiedAreaBBox();

                Image image = new Image(img);

                image.ScaleToFit(10000000, position.GetHeight());

                float x = position.GetLeft();
                float y = position.GetBottom();

                while (x + image.GetImageScaledWidth() < position.GetRight())
                {
                    image.SetFixedPosition(x, y);
                    canvas.AddImageFittedIntoRectangle(img, new Rectangle(x, y, image.GetImageScaledWidth(), image.GetImageScaledHeight()), false);
                    x += image.GetImageScaledWidth();
                }
            }
Esempio n. 19
0
            public override void Draw(DrawContext drawContext)
            {
                float     llx    = GetOccupiedAreaBBox().GetX() + 2;
                float     lly    = GetOccupiedAreaBBox().GetY() + 2;
                float     urx    = GetOccupiedAreaBBox().GetX() + GetOccupiedAreaBBox().GetWidth() - 2;
                float     ury    = GetOccupiedAreaBBox().GetY() + GetOccupiedAreaBBox().GetHeight() - 2;
                float     r      = 4;
                float     b      = 0.4477f;
                PdfCanvas canvas = drawContext.GetCanvas();

                canvas.MoveTo(llx, lly);
                canvas.LineTo(urx, lly);
                canvas.LineTo(urx, ury - r);
                canvas.CurveTo(urx, ury - r * b, urx - r * b, ury, urx - r, ury);
                canvas.LineTo(llx + r, ury);
                canvas.CurveTo(llx + r * b, ury, llx, ury - r * b, llx, ury - r);
                canvas.LineTo(llx, lly);
                canvas.Stroke();

                base.Draw(drawContext);
            }
Esempio n. 20
0
            public override void Draw(DrawContext drawContext)
            {
                PdfPattern.Tiling imgPattern = new PdfPattern.Tiling(img.GetWidth(), img.GetHeight(),
                                                                     img.GetWidth(), img.GetHeight());

                PdfPatternCanvas patternCanvas = new PdfPatternCanvas(imgPattern, drawContext.GetDocument());

                patternCanvas.AddImageAt(img, 0, 0, false);

                PdfCanvas canvas = drawContext.GetCanvas();

                canvas.SaveState();

                ColorRectangle(canvas, new PatternColor(imgPattern), GetOccupiedAreaBBox().GetX(),
                               GetOccupiedAreaBBox().GetY(), GetOccupiedAreaBBox().GetWidth(), GetOccupiedAreaBBox().GetHeight());

                canvas.SetFillColor(new PatternColor(imgPattern));
                canvas.Stroke();

                canvas.RestoreState();
            }
Esempio n. 21
0
            public override void Draw(DrawContext drawContext)
            {
                PdfCanvas canvas;
                float     llx = rows[row][0].GetOccupiedAreaBBox().GetLeft();
                float     lly = rows[row][0].GetOccupiedAreaBBox().GetBottom();
                float     urx = rows[row][rows[row].Length - 1].GetOccupiedAreaBBox().GetRight();
                float     ury = rows[row][0].GetOccupiedAreaBBox().GetTop();
                float     h   = ury - lly;

                canvas = drawContext.GetCanvas();
                canvas.SaveState();
                canvas.Arc(llx - h / 2, lly, llx + h / 2, ury, 90, 180);
                canvas.LineTo(urx, lly);
                canvas.Arc(urx - h / 2, lly, urx + h / 2, ury, 270, 180);
                canvas.LineTo(llx, ury);
                canvas.SetFillColor(ColorConstants.LIGHT_GRAY);
                canvas.Fill();
                canvas.RestoreState();

                base.Draw(drawContext);
            }
Esempio n. 22
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                // Draws a line to delimit the text every 25 words
                if (0 == count % 25)
                {
                    Rectangle textRect   = GetOccupiedAreaBBox();
                    int       pageNumber = GetOccupiedArea().GetPageNumber();
                    PdfCanvas canvas     = drawContext.GetCanvas();
                    Rectangle pageRect   = drawContext.GetDocument().GetPage(pageNumber).GetPageSize();
                    canvas
                    .SaveState()
                    .SetLineDash(5, 5)
                    .MoveTo(pageRect.GetLeft(), textRect.GetBottom())
                    .LineTo(textRect.GetRight(), textRect.GetBottom())
                    .LineTo(textRect.GetRight(), textRect.GetTop())
                    .LineTo(pageRect.GetRight(), textRect.GetTop())
                    .Stroke()
                    .RestoreState();
                }
            }
Esempio n. 23
0
            public override void DrawChildren(DrawContext drawContext)
            {
                base.DrawChildren(drawContext);
                PdfCanvas canvas = drawContext.GetCanvas();

                canvas.SetLineDash(1f, 3f);

                // first horizontal line
                CellRenderer[] cellRenderers = rows[0];
                canvas.MoveTo(cellRenderers[0].GetOccupiedArea().GetBBox().GetLeft(),
                              cellRenderers[0].GetOccupiedArea().GetBBox().GetTop());
                canvas.LineTo(cellRenderers[cellRenderers.Length - 1].GetOccupiedArea().GetBBox().GetRight(),
                              cellRenderers[cellRenderers.Length - 1].GetOccupiedArea().GetBBox().GetTop());

                foreach (CellRenderer[] renderers in rows)
                {
                    // horizontal lines
                    canvas.MoveTo(renderers[0].GetOccupiedArea().GetBBox().GetX(),
                                  renderers[0].GetOccupiedArea().GetBBox().GetY());
                    canvas.LineTo(renderers[renderers.Length - 1].GetOccupiedArea().GetBBox().GetRight(),
                                  renderers[renderers.Length - 1].GetOccupiedArea().GetBBox().GetBottom());

                    // first vertical line
                    Rectangle cellRect = renderers[0].GetOccupiedArea().GetBBox();
                    canvas.MoveTo(cellRect.GetLeft(), cellRect.GetBottom());
                    canvas.LineTo(cellRect.GetLeft(), cellRect.GetTop());

                    // vertical lines
                    foreach (CellRenderer renderer in renderers)
                    {
                        cellRect = renderer.GetOccupiedArea().GetBBox();
                        canvas.MoveTo(cellRect.GetRight(), cellRect.GetBottom());
                        canvas.LineTo(cellRect.GetRight(), cellRect.GetTop());
                    }
                }

                canvas.Stroke();
            }
Esempio n. 24
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfCanvas canvas   = drawContext.GetCanvas();
                Rectangle position = GetOccupiedAreaBBox();

                canvas.SaveState();
                canvas.SetLineDash(1f, 3f);

                if (borders[0])
                {
                    canvas.MoveTo(position.GetRight(), position.GetTop());
                    canvas.LineTo(position.GetLeft(), position.GetTop());
                }

                if (borders[2])
                {
                    canvas.MoveTo(position.GetRight(), position.GetBottom());
                    canvas.LineTo(position.GetLeft(), position.GetBottom());
                }

                if (borders[3])
                {
                    canvas.MoveTo(position.GetRight(), position.GetTop());
                    canvas.LineTo(position.GetRight(), position.GetBottom());
                }

                if (borders[1])
                {
                    canvas.MoveTo(position.GetLeft(), position.GetTop());
                    canvas.LineTo(position.GetLeft(), position.GetBottom());
                }

                canvas.Stroke();
                canvas.RestoreState();
            }
Esempio n. 25
0
 public override void Draw(DrawContext drawContext)
 {
     img.ScaleToFit(GetOccupiedAreaBBox().GetWidth(), GetOccupiedAreaBBox().GetHeight());
     drawContext.GetCanvas().AddXObjectFittedIntoRectangle(img.GetXObject(), GetOccupiedAreaBBox());
     base.Draw(drawContext);
 }
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);

                Rectangle area = GetOccupiedAreaBBox();

                img.ScaleToFit(area.GetWidth(), area.GetHeight());

                drawContext.GetCanvas().AddXObjectFittedIntoRectangle(img.GetXObject(), new Rectangle(
                                                                          area.GetX() + (area.GetWidth() - img.GetImageWidth() *
                                                                                         img.GetProperty <float>(Property.HORIZONTAL_SCALING)) / 2,
                                                                          area.GetY() + (area.GetHeight() - img.GetImageHeight() *
                                                                                         img.GetProperty <float>(Property.VERTICAL_SCALING)) / 2,
                                                                          img.GetImageWidth() * img.GetProperty <float>(Property.HORIZONTAL_SCALING),
                                                                          img.GetImageHeight() * img.GetProperty <float>(Property.VERTICAL_SCALING)));

                drawContext.GetCanvas().Stroke();

                Paragraph p       = new Paragraph(content);
                Leading   leading = p.GetDefaultProperty <Leading>(Property.LEADING);

                UnitValue defaultFontSizeUv = new DocumentRenderer(new Document(drawContext.GetDocument()))
                                              .GetPropertyAsUnitValue(Property.FONT_SIZE);

                float         defaultFontSize = defaultFontSizeUv.IsPointValue() ? defaultFontSizeUv.GetValue() : 12f;
                float         x;
                float         y;
                TextAlignment?alignment;

                switch (position)
                {
                case POSITION.TOP_LEFT:
                {
                    x         = area.GetLeft() + 3;
                    y         = area.GetTop() - defaultFontSize * leading.GetValue();
                    alignment = TextAlignment.LEFT;
                    break;
                }

                case POSITION.TOP_RIGHT:
                {
                    x         = area.GetRight() - 3;
                    y         = area.GetTop() - defaultFontSize * leading.GetValue();
                    alignment = TextAlignment.RIGHT;
                    break;
                }

                case POSITION.BOTTOM_LEFT:
                {
                    x         = area.GetLeft() + 3;
                    y         = area.GetBottom() + 3;
                    alignment = TextAlignment.LEFT;
                    break;
                }

                case POSITION.BOTTOM_RIGHT:
                {
                    x         = area.GetRight() - 3;
                    y         = area.GetBottom() + 3;
                    alignment = TextAlignment.RIGHT;
                    break;
                }

                default:
                {
                    x         = 0;
                    y         = 0;
                    alignment = TextAlignment.CENTER;
                    break;
                }
                }

                new Canvas(drawContext.GetCanvas(), area).ShowTextAligned(p, x, y, alignment);
            }