示例#1
0
            public virtual void HandleEvent(Event @event)
            {
                PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
                PdfDocument      pdfDoc   = docEvent.GetDocument();
                PdfPage          page     = docEvent.GetPage();
                int       pageNumber      = pdfDoc.GetPageNumber(page);
                Rectangle pageSize        = page.GetPageSize();
                PdfCanvas pdfCanvas       = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), pdfDoc);
                //Set background
                Color limeColor = new DeviceCmyk(0.208f, 0, 0.584f, 0);
                Color blueColor = new DeviceCmyk(0.445f, 0.0546f, 0, 0.0667f);

                pdfCanvas.SaveState().SetFillColor(pageNumber % 2 == 1 ? limeColor : blueColor).Rectangle(pageSize.GetLeft
                                                                                                              (), pageSize.GetBottom(), pageSize.GetWidth(), pageSize.GetHeight()).Fill().RestoreState();
                //Add header and footer
                pdfCanvas.BeginText().SetFontAndSize(C03E03_UFO.helvetica, 9).MoveText(pageSize.GetWidth() / 2 - 60, pageSize
                                                                                       .GetTop() - 20).ShowText("THE TRUTH IS OUT THERE").MoveText(60, -pageSize.GetTop() + 30).ShowText(pageNumber
                                                                                                                                                                                         .ToString()).EndText();
                //Add watermark
                iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, page.GetPageSize());
                canvas.SetFontColor(ColorConstants.WHITE);
                canvas.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(60));
                canvas.SetProperty(Property.FONT, C03E03_UFO.helveticaBold);
                canvas.ShowTextAligned(new Paragraph("CONFIDENTIAL"), 298, 421, pdfDoc.GetPageNumber(page), TextAlignment.
                                       CENTER, VerticalAlignment.MIDDLE, 45);
                pdfCanvas.Release();
            }
示例#2
0
        protected override void DrawTicks(PdfCanvas canvas, PdfPage page)
        {
            base.DrawTicks(canvas, page);

            try
            {
                float lastTickValue = float.Parse(_data.Columns[0].Label);

                iText.Layout.Canvas layoutCanvas = new iText.Layout.Canvas(canvas, _pdf, new iText.Kernel.Geom.Rectangle(_canvasWidth, _canvasHeight));
                layoutCanvas.SetFont(_font);
                layoutCanvas.SetFontSize(_valueFontSize);
                layoutCanvas.SetFontColor(_valueFontColour);

                canvas.SetLineWidth(_tickLineWidth).SetStrokeColor(_tickColour);

                float x = _originX;
                foreach (Column column in _data.Columns)
                {
                    float y           = _originY;
                    float columnValue = float.Parse(column.Label);

                    if (columnValue >= (lastTickValue + _lineXTicksInterval))
                    {
                        lastTickValue = columnValue;

                        canvas.MoveTo(x, _originY);
                        canvas.LineTo(x, _originY + _axisHeight * _yScale);

                        if (_columnLabelAngle == 0.0f)
                        {
                            layoutCanvas.ShowTextAligned(column.Label, x, _originY - _columnLabelMargin, TextAlignment.CENTER, VerticalAlignment.TOP, (float)Math.PI / 180.0f * _columnLabelAngle);
                        }
                        else if (_columnLabelAngle == 90.0f)
                        {
                            layoutCanvas.ShowTextAligned(column.Label, x, _originY - _columnLabelMargin, TextAlignment.RIGHT, VerticalAlignment.MIDDLE, (float)Math.PI / 180.0f * _columnLabelAngle);
                        }
                        else
                        {
                            layoutCanvas.ShowTextAligned(column.Label, x, _originY - _columnLabelMargin, TextAlignment.RIGHT, VerticalAlignment.TOP, (float)Math.PI / 180.0f * _columnLabelAngle);
                        }
                    }


                    x += _linePointSpace;
                }
                canvas.Stroke();
            }
            catch
            {
                // not numeric column values, bail
                return;
            }
        }
示例#3
0
        protected override void DrawLabels(PdfCanvas canvas, PdfPage page)
        {
            iText.Layout.Canvas layoutCanvas = new iText.Layout.Canvas(canvas, _pdf, new iText.Kernel.Geom.Rectangle(_canvasWidth, _canvasHeight));
            layoutCanvas.SetFont(_font);
            layoutCanvas.SetFontSize(_valueFontSize);
            layoutCanvas.SetFontColor(_valueFontColour);
            float x;

            if (_data.ValueLabel != null)
            {
                x = _originX - _valueLabelMargin;
                layoutCanvas.ShowTextAligned(_data.ValueLabel, x, _originY + _axisHeight * _yScale / 2, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0.5f * (float)Math.PI);
            }

            if (_data.Legends.Count == 1)
            {
                layoutCanvas.ShowTextAligned(_data.Legends[0].Label, _originX + _axisWidth / 2, _originY - _valueLabelMargin, TextAlignment.CENTER, VerticalAlignment.MIDDLE, 0);
            }
        }
示例#4
0
        protected override void DrawTicks(PdfCanvas canvas, PdfPage page)
        {
            float  i;
            String text;
            float  textWidth;
            float  textHeight;

            double yOffset = 0;

            if (_tickLineWidth == 0.0f)
            {
                return;
            }

            if (_yAxisMin < 0)
            {
                yOffset = _yAxisMin * -1.0 * _yScale;
            }

            canvas.SetLineWidth(_tickLineWidth).SetStrokeColor(_tickColour);
            // DrawTicks
            for (i = (_yAxisMin + _valueAxisInterval); i <= _valueAxisMax; i += _valueAxisInterval)
            {
                text = i.ToString();
                if (_data.FormatPercent)
                {
                    text = text + "%";
                }
                textWidth  = _font.GetWidth(text, _tickFontSize) + _tickLabelMargin;
                textHeight = _font.GetAscent(text, _tickFontSize) + _font.GetDescent(text, _tickFontSize);

                canvas.MoveTo(_originX, _originY + i * _yScale + yOffset);
                canvas.LineTo(_originX + _axisWidth, _originY + i * _yScale + yOffset);

                canvas.BeginText()
                .SetFontAndSize(_font, _tickFontSize)
                .MoveText(_originX - textWidth, _originY + i * _yScale - textHeight / 2 + yOffset)
                .SetColor(_tickFontColour, true)
                .ShowText(text)
                .EndText();
            }
            canvas.Stroke();

            if (_lineXTicks)
            {
                float lastTickValue = float.Parse(_data.Columns[0].Label);

                iText.Layout.Canvas layoutCanvas = new iText.Layout.Canvas(canvas, _pdf, new iText.Kernel.Geom.Rectangle(_canvasWidth, _canvasHeight));
                layoutCanvas.SetFont(_font);
                layoutCanvas.SetFontSize(_valueFontSize);
                layoutCanvas.SetFontColor(_valueFontColour);

                canvas.SetLineWidth(_tickLineWidth).SetStrokeColor(_tickColour);

                float x      = _originX;
                int   xIndex = 0;
                for (xIndex = 0; xIndex < _pointCount; xIndex += (int)_lineXTicksInterval)
                {
                    float y = _originY;

                    canvas.MoveTo(_originX + xIndex * _linePointSpace, _originY);
                    canvas.LineTo(_originX + xIndex * _linePointSpace, _originY + _axisHeight * _yScale);
                }
                canvas.Stroke();
            }
        }