Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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();
            }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
 /// <summary>Places retrieved text to canvas to a separate layer.</summary>
 /// <param name="imageSize">
 /// size of the image according to the selected
 /// <see cref="ScaleMode"/>
 /// </param>
 /// <param name="pageText">text that was found on this image (or on this page)</param>
 /// <param name="pdfCanvas">canvas to place the text</param>
 /// <param name="multiplier">coefficient to adjust text placing on canvas</param>
 /// <param name="pageMediaBox">page parameters</param>
 private void AddTextToCanvas(Rectangle imageSize, IList <TextInfo> pageText, PdfCanvas pdfCanvas, float multiplier
                              , Rectangle pageMediaBox)
 {
     if (pageText != null && pageText.Count > 0)
     {
         Point imageCoordinates = PdfCreatorUtil.CalculateImageCoordinates(ocrPdfCreatorProperties.GetPageSize(), imageSize
                                                                           );
         foreach (TextInfo item in pageText)
         {
             String        line         = item.GetText();
             IList <float> coordinates  = item.GetBbox();
             float         left         = coordinates[0] * multiplier;
             float         right        = (coordinates[2] + 1) * multiplier - 1;
             float         top          = coordinates[1] * multiplier;
             float         bottom       = (coordinates[3] + 1) * multiplier - 1;
             float         bboxWidthPt  = PdfCreatorUtil.GetPoints(right - left);
             float         bboxHeightPt = PdfCreatorUtil.GetPoints(bottom - top);
             FontProvider  fontProvider = GetOcrPdfCreatorProperties().GetFontProvider();
             String        fontFamily   = GetOcrPdfCreatorProperties().GetDefaultFontFamily();
             if (!String.IsNullOrEmpty(line) && bboxHeightPt > 0 && bboxWidthPt > 0)
             {
                 Document document = new Document(pdfCanvas.GetDocument());
                 document.SetFontProvider(fontProvider);
                 // Scale the text width to fit the OCR bbox
                 float fontSize             = PdfCreatorUtil.CalculateFontSize(document, line, fontFamily, bboxHeightPt, bboxWidthPt);
                 float lineWidth            = PdfCreatorUtil.GetRealLineWidth(document, line, fontFamily, fontSize);
                 float deltaX               = PdfCreatorUtil.GetPoints(left);
                 float deltaY               = imageSize.GetHeight() - PdfCreatorUtil.GetPoints(bottom);
                 iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, pageMediaBox);
                 canvas.SetFontProvider(fontProvider);
                 Text      text      = new Text(line).SetHorizontalScaling(bboxWidthPt / lineWidth);
                 Paragraph paragraph = new Paragraph(text).SetMargin(0).SetMultipliedLeading(1.2f);
                 paragraph.SetFontFamily(fontFamily).SetFontSize(fontSize);
                 paragraph.SetWidth(bboxWidthPt * 1.5f);
                 if (ocrPdfCreatorProperties.GetTextColor() != null)
                 {
                     paragraph.SetFontColor(ocrPdfCreatorProperties.GetTextColor());
                 }
                 else
                 {
                     paragraph.SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.INVISIBLE);
                 }
                 canvas.ShowTextAligned(paragraph, deltaX + (float)imageCoordinates.x, deltaY + (float)imageCoordinates.y,
                                        TextAlignment.LEFT);
                 canvas.Close();
             }
         }
     }
 }
Exemplo n.º 5
0
            public virtual void HandleEvent(Event @event)
            {
                PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
                PdfDocument      pdf      = docEvent.GetDocument();
                PdfPage          page     = docEvent.GetPage();
                int       pageNumber      = pdf.GetPageNumber(page);
                Rectangle pageSize        = page.GetPageSize();
                PdfCanvas pdfCanvas       = new PdfCanvas(page.GetLastContentStream(), page.GetResources(), pdf);

                iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, pdf, pageSize);
                Paragraph           p      = new Paragraph().Add("Page ").Add(pageNumber.ToString()).Add(" of");

                canvas.ShowTextAligned(p, this.x, this.y, TextAlignment.RIGHT);
                pdfCanvas.AddXObject(this.placeholder, this.x + this.space, this.y - this.descent);
                canvas.Close();
            }
Exemplo n.º 6
0
            public virtual void HandleEvent(Event @event)
            {
                PdfDocumentEvent docEvent = (PdfDocumentEvent)@event;
                PdfDocument      pdf      = docEvent.GetDocument();
                PdfPage          page     = docEvent.GetPage();

                if (pdf.GetPageNumber(page) == 1)
                {
                    return;
                }
                Rectangle pageSize  = page.GetPageSize();
                PdfCanvas pdfCanvas = new PdfCanvas(page.GetLastContentStream(), page.GetResources(), pdf);

                iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, pageSize);
                canvas.ShowTextAligned(this.header, pageSize.GetWidth() / 2, pageSize.GetTop() - 30, TextAlignment.CENTER);
            }
Exemplo n.º 7
0
 public virtual void WriteTotal(PdfDocument pdf)
 {
     iText.Layout.Canvas canvas = new iText.Layout.Canvas(this.placeholder, pdf);
     canvas.ShowTextAligned(pdf.GetNumberOfPages().ToString(), 0, this.descent, TextAlignment.LEFT);
 }