public static string GetUnitVerbalization(UnitValue uv)
 {
     var res = "";
     if (uv.Value > 0)
     {
         res = res + VerbalizeDecimal(uv.Value);
         res = res + " " + uv.Unit;
         if(uv.Unit != "")
         {
             if (uv.Adjust != "")
             {
                 res = res + "/" + uv.Adjust;
             }
             if (uv.Total != "")
             {
                 res = res + "/" + uv.Total;
             }
             if(uv.Time != "")
             {
                 res = res + "/" + uv.Time;
             }
         }
     }
     return res;
 }
 /*
  * Create a new combination with a list of properties
  */
 public ContinuousCombination(UnitValue continuousProperty, UnitValue totalProperty, UnitValue property2, UnitValue property3)
 {
     //_continuousProperty = continuousProperty;
     //_properties.Add(totalProperty);
     //_properties.Add(property2);
     //_properties.Add(property3);
 }
 private static bool CompareUnitValue(UnitValue x, UnitValue y)
 {
     return (
         x.BaseValue == y.BaseValue &&
         x.Value == y.Value &&
         x.Unit == y.Unit &&
         x.Time == y.Time &&
         x.Adjust == y.Adjust &&
         x.Total == y.Total
     );
 }
Exemple #4
0
        public static UnitValue AssembleUnitValue(UnitValue unitValue, UnitValueDto unitValueDto)
        {
            if(unitValue == null) unitValue = UnitValue.NewUnitValue();
            if (unitValueDto == null) unitValueDto = new UnitValueDto();
            unitValue.Value = unitValueDto.value;
            unitValue.Unit = unitValueDto.unit;

            unitValue.ChangedByUser = unitValueDto.changedByUser;
            unitValue.Adjust = unitValueDto.adjustUnit;
            unitValue.Time = unitValueDto.timeUnit;
            unitValue.Total = unitValueDto.totalUnit;

            unitValue.UIState = unitValueDto.state;
            return unitValue;
        }
Exemple #5
0
        public static UnitValueDto AssembleUnitValueDto(UnitValue unitValue)
        {
            var unitValueDto = new UnitValueDto();
            if (unitValue == null) unitValue = UnitValue.NewUnitValue();

            unitValueDto.value = unitValue.Value;
            unitValueDto.unit = unitValue.Unit;

            unitValueDto.adjustUnit = unitValue.Adjust;
            unitValueDto.timeUnit = unitValue.Time;
            unitValueDto.totalUnit = unitValue.Total;
            unitValueDto.state = unitValue.UIState;

            return unitValueDto;
        }
        public string VerbalizeUnitValueExplanation(UnitValue unitValue1, UnitValue unitValue2)
        {
            string result = "";

            if(unitValue1.Value > 0)
                result = result + GetUnitVerbalization(unitValue1);

            if (unitValue1.Value > 0 && unitValue2.Value > 0)
                result = result + " = ";

            if(unitValue2.Value > 0)
                result = result + GetUnitVerbalization(unitValue2);

            return result;
        }
Exemple #7
0
        public PdfManager GenerateRevenueReport(DateTime?fromDate = null, DateTime?toDate = null)
        {
            DealService _dealService    = new DealService();
            FileInfo    file            = new FileInfo(pdfDestination);
            var         fontDestination = System.IO.Path.Combine(targetFolder, "times.ttf");

            //document settings
            pdfDoc = new PdfDocument(new PdfWriter(pdfDestination));
            pdfDoc.SetDefaultPageSize(PageSize.A4);
            document = new Document(pdfDoc, PageSize.A4, false).SetFontSize(12);
            //set header
            PdfFont font = PdfFontFactory.CreateFont(fontDestination, PdfEncodings.IDENTITY_H, true);
            PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);

            Paragraph docHeader = new Paragraph("Revenue Report").SetTextAlignment(TextAlignment.CENTER)
                                  .SetFontSize(headerFontSize).SetFont(bold);
            //set logo
            Image logo = new Image(ImageDataFactory
                                   .Create(logoFile))
                         .SetTextAlignment(TextAlignment.LEFT).SetHeight(60).SetWidth(60);

            document.Add(logo);
            document.Add(docHeader);

            if (fromDate != null && toDate != null)
            {
                var fromTo = new Paragraph("From " + fromDate.Value.ToString("D") + " to " + toDate.Value.ToString("D")).SetTextAlignment(TextAlignment.RIGHT).SetMarginRight(30);
                document.Add(fromTo);
            }

            var   currentItem = 1;
            Table table       = new Table(UnitValue.CreatePercentArray(6), false).SetFont(font);

            table.SetWidth(UnitValue.CreatePercentValue(100));
            table.SetFixedLayout();

            List <string> headers = new List <string> {
                "No.", "Deal's Name", "Closing Date", "Amount", "Customer's Name", "Owner"
            };

            foreach (var header in headers)
            {
                var newHeaderCell = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph(header));
                table.AddHeaderCell(newHeaderCell);
            }

            var dealList = _dealService.GetDealList(pageSize: 99999, currentPage: 1, sort: new List <string> {
                "asc.name"
            });

            dealList.deals = dealList.deals.Where(c => c.createdAt.CompareTo(new DateTime(1, 1, 1)) != 0 || c.endOn.CompareTo(new DateTime(1, 1, 1)) != 0 || c.expectedDate.CompareTo(new DateTime(1, 1, 1)) != 0).ToList();
            if (fromDate != null && toDate != null)
            {
                dealList.deals = dealList.deals.Where(c => (c.endOn >= fromDate && c.endOn <= toDate) && (c.stage == "Won")).ToList();
            }

            foreach (var deal in dealList.deals)
            {
                var x = deal.expectedDate.CompareTo(new DateTime(1, 1, 1)) != 0;
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(currentItem.ToString())));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(deal.name ?? "")));

                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(deal.endOn.CompareTo(new DateTime(1, 1, 1)) != 0 ? deal.endOn.ToString("dd'/'MM'/'yyyy") : "")));

                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(deal.amount.ToString() ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(deal.accountName ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(deal.owner ?? "")));
                currentItem++;
            }
            long totalAmount = dealList.deals.Aggregate((long)0, (total, next) => total += next.amount, res => res);

            table.AddCell(new Cell(1, 3).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph("Sum")));
            table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetBorderRight(Border.NO_BORDER).SetFontSize(fontSize).Add(new Paragraph(totalAmount.ToString())));
            table.AddCell(new Cell(1, 2).SetTextAlignment(TextAlignment.CENTER).SetBorderLeft(Border.NO_BORDER).SetFontSize(fontSize).Add(new Paragraph("")));
            document.Add(table);

            document.Add(new Paragraph(new Text("\n")));

            var dateSignature = new Paragraph("Hanoi, " + DateTime.Now.ToString("D")).SetTextAlignment(TextAlignment.RIGHT).SetMarginRight(30);

            document.Add(dateSignature);
            document.Add(new Paragraph(new Text("\n\n")));
            document.Add(new Paragraph(new Text("Signature: ________________________")).SetTextAlignment(TextAlignment.RIGHT).SetMarginRight(0));


            int numberOfPages = pdfDoc.GetNumberOfPages();

            for (int i = 1; i <= numberOfPages; i++)
            {
                document.ShowTextAligned(new Paragraph(String
                                                       .Format(i.ToString())),
                                         559, PageSize.A4.GetBottom() + 20, i, TextAlignment.RIGHT,//806
                                         VerticalAlignment.BOTTOM, 0);
            }
            document.Close();
            return(this);
        }
Exemple #8
0
        public void CreatePDF8x6(BarcodeReading barcodeReading, string color)
        {
            PdfWriter   writer = new PdfWriter(string.Format(@"..\..\Labels\{0}.pdf", barcodeReading.Barcode));
            PdfDocument pdf    = new PdfDocument(writer);

            pdf.SetDefaultPageSize(new iText.Kernel.Geom.PageSize(new iText.Kernel.Geom.Rectangle(768, 384)));
            Document document = new Document(pdf);

            document.SetMargins(0, 0, 0, 0);

            QRCodeGenerator qr   = new QRCodeGenerator();
            QRCodeData      data = qr.CreateQrCode(barcodeReading.Barcode, QRCodeGenerator.ECCLevel.Q);
            QRCode          code = new QRCode(data);

            Image logo = new Image(ImageDataFactory
                                   .Create(@"..\..\Images\full-logo.png"))
                         .SetTextAlignment(TextAlignment.CENTER);

            Image imgQR = new Image(ImageDataFactory
                                    .Create((System.Drawing.Image)code.GetGraphic(5, System.Drawing.Color.Black, System.Drawing.Color.White, false), null))
                          .SetTextAlignment(TextAlignment.CENTER).SetWidth(new UnitValue(UnitValue.PERCENT, 83));

            UnitValue[] columnWidths = new UnitValue[] {
                new UnitValue(UnitValue.PERCENT, 14),
                new UnitValue(UnitValue.PERCENT, 18),
                new UnitValue(UnitValue.PERCENT, float.Parse((20.4).ToString())),
                new UnitValue(UnitValue.PERCENT, 18),
                new UnitValue(UnitValue.PERCENT, 18),
                new UnitValue(UnitValue.PERCENT, 14),
            };


            Table table = new Table(columnWidths);

            table.SetFixedLayout();
            table.SetWidth(new UnitValue(UnitValue.PERCENT, 100));

            table.SetBorder(Border.NO_BORDER);
            Cell cellQRTL = new Cell(2, 1).SetBorder(Border.NO_BORDER);

            cellQRTL.Add(imgQR);

            Cell cellLogo = new Cell(1, 4).SetBorder(Border.NO_BORDER);

            cellLogo.Add(logo.SetHeight(50).SetMarginLeft(175).SetMarginTop(10).SetMarginBottom(10));

            Cell cellQRTR = new Cell(2, 1).SetBorder(Border.NO_BORDER);

            cellQRTR.Add(imgQR);

            Table centralContent = new Table(new UnitValue[] {
                new UnitValue(UnitValue.PERCENT, 23),
                new UnitValue(UnitValue.PERCENT, 23),
                new UnitValue(UnitValue.PERCENT, 6),
                new UnitValue(UnitValue.PERCENT, 24),
                new UnitValue(UnitValue.PERCENT, 19),
                new UnitValue(UnitValue.PERCENT, 5)
            });

            centralContent.SetWidth(new UnitValue(UnitValue.PERCENT, 100));
            centralContent.SetBorder(Border.NO_BORDER).SetAutoLayout();

            //centralContent.AddCell(new Cell(3, 1).SetBorder(Border.NO_BORDER).SetMargin(0).SetPadding(0));
            Paragraph pJob = new Paragraph("JOB\n").SetTextAlignment(TextAlignment.LEFT);

            pJob.Add(new Paragraph(barcodeReading.Job)
                     .SetFontSize(36)
                     .SetStrokeWidth(1f)
                     .SetStrokeColor(DeviceGray.BLACK)
                     .SetBorder(new SolidBorder(1))
                     .SetPaddingLeft(15)
                     .SetPaddingRight(15)
                     .SetPaddingTop(5)
                     .SetPaddingBottom(5)
                     .SetWidth(new UnitValue(UnitValue.PERCENT, 80))
                     .SetTextAlignment(TextAlignment.CENTER)
                     );

            Cell jobCell = new Cell(3, 2).SetBorder(Border.NO_BORDER);

            jobCell.Add(pJob);
            centralContent.AddCell(jobCell);
            centralContent.AddCell(new Cell(3, 1).SetBorder(Border.NO_BORDER));
            Paragraph pFloor = new Paragraph("FLOOR\n").SetBorder(Border.NO_BORDER).SetMarginLeft(0).SetPaddingLeft(0);

            pFloor.Add(new Paragraph(barcodeReading.Floor)
                       .SetFontSize(36)
                       .SetStrokeWidth(.9f)
                       .SetStrokeColor(DeviceGray.BLACK)
                       .SetBorder(new SolidBorder(1))
                       .SetPaddingLeft(15)
                       .SetPaddingRight(15)
                       .SetPaddingTop(5)
                       .SetPaddingBottom(5)
                       .SetWidth(new UnitValue(UnitValue.PERCENT, 100))
                       .SetTextAlignment(TextAlignment.CENTER)
                       );

            Cell floorCell = new Cell(3, 4).SetBorder(Border.NO_BORDER);

            floorCell.Add(pFloor);
            centralContent.AddCell(floorCell);

            Paragraph pTag = new Paragraph("TAG\n").SetBorder(Border.NO_BORDER);

            pTag.Add(new Paragraph(barcodeReading.Tag)
                     .SetFontSize(45)
                     .SetStrokeWidth(.9f)
                     .SetStrokeColor(DeviceGray.BLACK)
                     .SetBorder(new SolidBorder(1))
                     .SetPaddingLeft(15)
                     .SetPaddingRight(15)
                     .SetPaddingTop(5)
                     .SetPaddingBottom(5)
                     .SetWidth(new UnitValue(UnitValue.PERCENT, 100))
                     .SetTextAlignment(TextAlignment.CENTER)
                     );

            Cell tagCell = new Cell(3, 6).SetBorder(Border.NO_BORDER);

            tagCell.Add(pTag);
            centralContent.AddCell(tagCell);



            Cell cellCentralContent = new Cell(2, 4).SetBorder(Border.NO_BORDER);

            cellCentralContent.Add(centralContent);
            table.AddCell(cellQRTL);
            table.AddCell(cellLogo);
            table.AddCell(cellQRTR);
            //table.AddCell(new Cell(2, 1).SetBorder(Border.NO_BORDER).SetBackgroundColor(GetRgb(color)));
            table.AddCell(cellCentralContent);

            Table leftColor = new Table(new UnitValue[] {
                new UnitValue(UnitValue.PERCENT, 60),
                new UnitValue(UnitValue.PERCENT, 40)
            });

            leftColor.SetWidth(new UnitValue(UnitValue.PERCENT, 100));
            leftColor.SetBorder(Border.NO_BORDER);
            leftColor.SetMarginTop(25);
            leftColor.SetMarginBottom(25);
            leftColor.SetHeight(new UnitValue(UnitValue.POINT, 150));

            Paragraph pleftColor = new Paragraph();

            leftColor.AddCell(new Cell(5, 1).Add(pleftColor).SetBorder(Border.NO_BORDER).SetBackgroundColor(GetRgb(color)));

            Cell cellLeftColor = new Cell(1, 1).SetBorder(Border.NO_BORDER);

            cellLeftColor.Add(leftColor);



            table.AddCell(cellLeftColor);


            Table rightColor = new Table(new UnitValue[] {
                new UnitValue(UnitValue.PERCENT, 40),
                new UnitValue(UnitValue.PERCENT, 60)
            });

            rightColor.SetWidth(new UnitValue(UnitValue.POINT, 106));
            rightColor.SetBorder(Border.NO_BORDER);
            rightColor.SetMarginTop(25);
            rightColor.SetMarginLeft(36);
            rightColor.SetMarginBottom(25);
            rightColor.SetHeight(new UnitValue(UnitValue.POINT, 150));

            Paragraph prightColor = new Paragraph();

            rightColor.AddCell(new Cell(5, 1).Add(prightColor).SetBorder(Border.NO_BORDER).SetBackgroundColor(GetRgb(color)));

            Cell cellRightColor = new Cell(1, 1).SetBorder(Border.NO_BORDER);

            cellRightColor.Add(rightColor);


            table.AddCell(cellRightColor);


            Cell cellQRTL2 = new Cell(2, 1).SetBorder(Border.NO_BORDER);

            cellQRTL2.Add(imgQR);

            Table tableBottom = new Table(new UnitValue[] {
                new UnitValue(UnitValue.PERCENT, 5),
                new UnitValue(UnitValue.PERCENT, 19),
                new UnitValue(UnitValue.PERCENT, 19),
                new UnitValue(UnitValue.PERCENT, 19),
                new UnitValue(UnitValue.PERCENT, 19),
                new UnitValue(UnitValue.PERCENT, 19)
            });

            tableBottom.SetWidth(new UnitValue(UnitValue.PERCENT, 90)).SetTextAlignment(TextAlignment.CENTER);
            tableBottom.SetMarginLeft(30);
            tableBottom.SetBorder(Border.NO_BORDER);


            Paragraph pDate         = new Paragraph("DATE:").SetTextAlignment(TextAlignment.LEFT).SetFontSize(14);
            Paragraph pDateTimeInfo = new Paragraph(barcodeReading.ScanDate.ToString("MMM-dd-yyyy hh:mm tt").ToUpper()).SetTextAlignment(TextAlignment.LEFT).SetFontSize(14);
            Paragraph pLine         = new Paragraph(string.Format("L{0}", barcodeReading.Line.ToString())).SetTextAlignment(TextAlignment.LEFT).SetFontSize(18);


            tableBottom.AddCell(new Cell(1, 2).Add(pDate).SetBorder(Border.NO_BORDER));
            tableBottom.AddCell(new Cell(1, 3).Add(pDateTimeInfo).SetBorder(Border.NO_BORDER));
            tableBottom.AddCell(new Cell(1, 1).Add(pLine).SetBorder(Border.NO_BORDER));


            tableBottom.AddCell(new Cell(1, 6).Add(new Paragraph()).SetBorder(Border.NO_BORDER).SetTextAlignment(TextAlignment.CENTER).SetMarginLeft(10).SetWidth(new UnitValue(UnitValue.PERCENT, 100)).SetBackgroundColor(GetRgb(color)).SetHeight(new UnitValue(UnitValue.POINT, 35)));
            Cell cellQRTR2 = new Cell(2, 1).SetBorder(Border.NO_BORDER);

            cellQRTR2.Add(imgQR);

            table.AddCell(cellQRTL2);
            table.AddCell(new Cell(1, 4).Add(tableBottom).SetBorder(Border.NO_BORDER));
            table.AddCell(cellQRTR2);


            document.Add(table);

            document.Close();
        }
Exemple #9
0
        public void AsReturnsObjectIfSameType()
        {
            var unitValue = new UnitValue(CompoundUnits.Kilogram, 10);

            Assert.That(unitValue.As <UnitValue>(), Is.EqualTo(unitValue));
        }
Exemple #10
0
        /// <summary>Applies paddings to an element.</summary>
        /// <param name="cssProps">the CSS properties</param>
        /// <param name="context">the processor context</param>
        /// <param name="element">the element</param>
        /// <param name="baseValueHorizontal">value used by default for horizontal dimension</param>
        /// <param name="baseValueVertical">value used by default for vertical dimension</param>
        public static void ApplyPaddings(IDictionary <String, String> cssProps, ProcessorContext context, IPropertyContainer
                                         element, float baseValueVertical, float baseValueHorizontal)
        {
            String    paddingTop       = cssProps.Get(CssConstants.PADDING_TOP);
            String    paddingBottom    = cssProps.Get(CssConstants.PADDING_BOTTOM);
            String    paddingLeft      = cssProps.Get(CssConstants.PADDING_LEFT);
            String    paddingRight     = cssProps.Get(CssConstants.PADDING_RIGHT);
            float     em               = CssDimensionParsingUtils.ParseAbsoluteLength(cssProps.Get(CssConstants.FONT_SIZE));
            float     rem              = context.GetCssContext().GetRootFontSize();
            UnitValue paddingTopVal    = CssDimensionParsingUtils.ParseLengthValueToPt(paddingTop, em, rem);
            UnitValue paddingBottomVal = CssDimensionParsingUtils.ParseLengthValueToPt(paddingBottom, em, rem);
            UnitValue paddingLeftVal   = CssDimensionParsingUtils.ParseLengthValueToPt(paddingLeft, em, rem);
            UnitValue paddingRightVal  = CssDimensionParsingUtils.ParseLengthValueToPt(paddingRight, em, rem);

            if (paddingTopVal != null)
            {
                if (paddingTopVal.IsPointValue())
                {
                    element.SetProperty(Property.PADDING_TOP, paddingTopVal);
                }
                else
                {
                    if (baseValueVertical != 0.0f)
                    {
                        element.SetProperty(Property.PADDING_TOP, new UnitValue(UnitValue.POINT, baseValueVertical * paddingTopVal
                                                                                .GetValue() * 0.01f));
                    }
                    else
                    {
                        logger.Error(iText.Html2pdf.LogMessageConstant.PADDING_VALUE_IN_PERCENT_NOT_SUPPORTED);
                    }
                }
            }
            if (paddingBottomVal != null)
            {
                if (paddingBottomVal.IsPointValue())
                {
                    element.SetProperty(Property.PADDING_BOTTOM, paddingBottomVal);
                }
                else
                {
                    if (baseValueVertical != 0.0f)
                    {
                        element.SetProperty(Property.PADDING_BOTTOM, new UnitValue(UnitValue.POINT, baseValueVertical * paddingBottomVal
                                                                                   .GetValue() * 0.01f));
                    }
                    else
                    {
                        logger.Error(iText.Html2pdf.LogMessageConstant.PADDING_VALUE_IN_PERCENT_NOT_SUPPORTED);
                    }
                }
            }
            if (paddingLeftVal != null)
            {
                if (paddingLeftVal.IsPointValue())
                {
                    element.SetProperty(Property.PADDING_LEFT, paddingLeftVal);
                }
                else
                {
                    if (baseValueHorizontal != 0.0f)
                    {
                        element.SetProperty(Property.PADDING_LEFT, new UnitValue(UnitValue.POINT, baseValueHorizontal * paddingLeftVal
                                                                                 .GetValue() * 0.01f));
                    }
                    else
                    {
                        logger.Error(iText.Html2pdf.LogMessageConstant.PADDING_VALUE_IN_PERCENT_NOT_SUPPORTED);
                    }
                }
            }
            if (paddingRightVal != null)
            {
                if (paddingRightVal.IsPointValue())
                {
                    element.SetProperty(Property.PADDING_RIGHT, paddingRightVal);
                }
                else
                {
                    if (baseValueHorizontal != 0.0f)
                    {
                        element.SetProperty(Property.PADDING_RIGHT, new UnitValue(UnitValue.POINT, baseValueHorizontal * paddingRightVal
                                                                                  .GetValue() * 0.01f));
                    }
                    else
                    {
                        logger.Error(iText.Html2pdf.LogMessageConstant.PADDING_VALUE_IN_PERCENT_NOT_SUPPORTED);
                    }
                }
            }
        }
Exemple #11
0
 public UnitValue <S, T> Convert(UnitValue <S, T> valueSource, UnitValue <S, T> valueTarget)
 {
     return(Multiply(Convert(Divide(valueSource, valueTarget)), valueTarget));
 }
 /// <summary>
 /// Returns the value range given a plot area coordinate.
 /// </summary>
 /// <param name="value">The plot area coordinate.</param>
 /// <returns>A range of values at that plot area coordinate.</returns>
 protected abstract IComparable GetValueAtPosition(UnitValue value);
        private static void SetUnitWithTimeAndAdjust(string input, UnitValue uv)
        {
            var inputSplit = input.Trim().Split('/');

            uv.Unit = inputSplit[0].Trim();

            if (inputSplit.Length == 2)
                uv.Time = inputSplit[1].Trim();

            if (inputSplit.Length == 3)
            {
                uv.Time = inputSplit[1].Trim();
                uv.Adjust = inputSplit[2].Trim();
            }
        }
 /// <summary>
 /// Creates a
 /// <see cref="BorderRadius">border radius</see>
 /// with given horizontal and vertical values.
 /// </summary>
 /// <param name="horizontalRadius">the horizontal radius of the corner</param>
 /// <param name="verticalRadius">the vertical radius of the corner</param>
 public BorderRadius(UnitValue horizontalRadius, UnitValue verticalRadius)
 {
     this.horizontalRadius = horizontalRadius;
     this.verticalRadius   = verticalRadius;
 }
        /// <summary>
        /// Returns the value range given a plot area coordinate.
        /// </summary>
        /// <param name="value">The plot area position.</param>
        /// <returns>The value at that plot area coordinate.</returns>
        protected override IComparable GetValueAtPosition(UnitValue value)
        {
            if (ActualRange.HasData && ActualLength != 0.0)
            {
                if (value.Unit == Unit.Pixels)
                {
                    double coordinate = value.Value;
                    Range<double> actualDoubleRange = ActualRange.ToDoubleRange();

                    double rangelength = actualDoubleRange.Maximum - actualDoubleRange.Minimum;
                    double output = ((coordinate * (rangelength / ActualLength)) + actualDoubleRange.Minimum);

                    return output;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return null;
        }
 private static void SetUnitWithTotal(string input, UnitValue uv)
 {
     var inputSplit = input.Trim().Split('/');
     uv.Unit = inputSplit[0].Trim();
     uv.Total = inputSplit[1].Trim();
 }
Exemple #17
0
 public void TryConvertReturnsFalseOnIncompatibleUnits()
 {
     var val = new UnitValue(1, Unit.Meter);
     double newValue;
     Assert.False(val.TryConvert(Unit.Second, out newValue));
 }
 private static void SetValueWithUnitTotal(string input, UnitValue uv)
 {
     uv.Value = ExtractValue(input);
     string units = ExtractUnits(input);
     if (units != "") SetUnitWithTotal(units, uv);
 }
Exemple #19
0
 public CompositionComponent(string componentId, string materialBatch, UnitValue amount)
 {
     ComponentId   = componentId;
     MaterialBatch = materialBatch;
     Amount        = amount;
 }
 /// <summary>
 /// Creates a
 /// <see cref="BorderRadius">border radius</see>
 /// with given horizontal and vertical point values.
 /// </summary>
 /// <param name="horizontalRadius">the horizontal radius of the corner</param>
 /// <param name="verticalRadius">the vertical radius of the corner</param>
 public BorderRadius(float horizontalRadius, float verticalRadius)
 {
     this.horizontalRadius = UnitValue.CreatePointValue(horizontalRadius);
     this.verticalRadius   = UnitValue.CreatePointValue(verticalRadius);
 }
 public static string GetfrequencyVerbalization(UnitValue frequency)
 {
     return ((frequency.Value > 0 && frequency.Time != "") ?
         VerbalizeDecimal(frequency.Value) + " keer per " + frequency.Time + " "
     :  "");
 }
Exemple #22
0
 public PageSizeInfo(UnitValue width, UnitValue height)
 {
     _width  = width;
     _height = height;
 }
        /// <summary>
        /// Returns the value range given a plot area coordinate.
        /// </summary>
        /// <param name="value">The plot area position.</param>
        /// <returns>The value at that plot area coordinate.</returns>
        protected override IComparable GetValueAtPosition(UnitValue value)
        {
            if (ActualRange.HasData && ActualLength != 0.0)
            {
                if (value.Unit == Unit.Pixels)
                {
                    double coordinate = value.Value;
                    Range<double> actualDoubleRange = ActualRange.ToDoubleRange();

                    double output =
                        Math.Pow
                        (
                            10,
                            coordinate *
                            Math.Log10(actualDoubleRange.Maximum / actualDoubleRange.Minimum) /
                            ActualLength
                        )
                        *
                        actualDoubleRange.Minimum;

                    return output;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return null;
        }
Exemple #24
0
        public virtual void DivWithRotatedPercentImage()
        {
            String          outFileName  = destinationFolder + "divRotatedPercentImage.pdf";
            String          cmpFileName  = sourceFolder + "cmp_divRotatedPercentImage.pdf";
            PdfDocument     pdfDocument  = new PdfDocument(new PdfWriter(outFileName));
            Document        doc          = new Document(pdfDocument);
            PdfImageXObject imageXObject = new PdfImageXObject(ImageDataFactory.Create(sourceFolder + "itis.jpg"));

            iText.Layout.Element.Image img = new iText.Layout.Element.Image(imageXObject).SetRotationAngle(Math.PI * 3
                                                                                                           / 8);
            Div d = new Div().Add(img).SetBorder(new SolidBorder(ColorConstants.BLUE, 2f)).SetMarginBottom(10);

            iText.Layout.Element.Image imgPercent = new iText.Layout.Element.Image(imageXObject).SetWidth(UnitValue.CreatePercentValue
                                                                                                              (50)).SetRotationAngle(Math.PI * 3 / 8);
            Div         dPercent = new Div().Add(imgPercent).SetBorder(new SolidBorder(ColorConstants.BLUE, 2f));
            MinMaxWidth result   = ((AbstractRenderer)d.CreateRendererSubTree().SetParent(doc.GetRenderer())).GetMinMaxWidth
                                       ();

            d.SetWidth(ToEffectiveWidth(d, result.GetMinWidth()));
            MinMaxWidth resultPercent = ((AbstractRenderer)dPercent.CreateRendererSubTree().SetParent(doc.GetRenderer(
                                                                                                          ))).GetMinMaxWidth();

            dPercent.SetWidth(ToEffectiveWidth(dPercent, resultPercent.GetMaxWidth()));
            doc.Add(d);
            doc.Add(dPercent);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
 private static void SetTime(string input, UnitValue uv)
 {
     var inputSplit = input.Trim().Split('/');
     uv.Time = inputSplit[0].Trim();
 }
Exemple #26
0
        public virtual void HeaderFooterTableTest()
        {
            String   outFileName = destinationFolder + "headerFooterTableTest.pdf";
            String   cmpFileName = sourceFolder + "cmp_headerFooterTableTest.pdf";
            Document doc         = new Document(new PdfDocument(new PdfWriter(outFileName)));
            Cell     bigCell     = new Cell().Add(new Paragraph("veryveryveryvery big cell")).SetBorder(new SolidBorder(ColorConstants
                                                                                                                        .RED, 40)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetPadding(0);
            Cell mediumCell = new Cell().Add(new Paragraph("mediumsize cell")).SetBorder(new SolidBorder(ColorConstants
                                                                                                         .GREEN, 30)).SetBorderBottom(Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetPadding(0);
            Cell cell = new Cell().Add(new Paragraph("cell")).SetBorder(new SolidBorder(ColorConstants.BLUE, 10)).SetBorderBottom
                            (Border.NO_BORDER).SetBorderTop(Border.NO_BORDER).SetPadding(0);
            Table table = new Table(UnitValue.CreatePercentArray(3)).UseAllAvailableWidth().SetBorder(new SolidBorder(
                                                                                                          ColorConstants.BLACK, 20)).AddCell(mediumCell.Clone(true)).AddCell(mediumCell.Clone(true)).AddCell(mediumCell
                                                                                                                                                                                                             .Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(bigCell.Clone
                                                                                                                                                                                                                                                                                                             (true)).AddHeaderCell(bigCell.Clone(true)).AddHeaderCell(cell.Clone(true)).AddHeaderCell(cell.Clone(true
                                                                                                                                                                                                                                                                                                                                                                                                                 ));
            TableRenderer renderer    = (TableRenderer)table.CreateRendererSubTree().SetParent(doc.GetRenderer());
            MinMaxWidth   minMaxWidth = renderer.GetMinMaxWidth();
            Table         minTable    = new Table(new float[] { -1, -1, -1 }).SetWidth(UnitValue.CreatePointValue(1)).SetBorder(new
                                                                                                                                SolidBorder(ColorConstants.BLACK, 20)).SetMarginTop(20).AddCell(mediumCell.Clone(true)).AddCell(mediumCell
                                                                                                                                                                                                                                .Clone(true)).AddCell(mediumCell.Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(cell.Clone
                                                                                                                                                                                                                                                                                                                                (true)).AddFooterCell(bigCell.Clone(true)).AddHeaderCell(bigCell.Clone(true)).AddHeaderCell(cell.Clone
                                                                                                                                                                                                                                                                                                                                                                                                                                (true)).AddHeaderCell(cell.Clone(true));
            Table maxTable = new Table(new float[] { -1, -1, -1 }).SetBorder(new SolidBorder(ColorConstants.BLACK, 20)
                                                                             ).SetMarginTop(20).AddCell(mediumCell.Clone(true)).AddCell(mediumCell.Clone(true)).AddCell(mediumCell.
                                                                                                                                                                        Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(cell.Clone(true)).AddFooterCell(bigCell.Clone
                                                                                                                                                                                                                                                                       (true)).AddHeaderCell(bigCell.Clone(true)).AddHeaderCell(cell.Clone(true)).AddHeaderCell(cell.Clone(true
                                                                                                                                                                                                                                                                                                                                                                           ));

            doc.Add(table);
            doc.Add(minTable);
            doc.Add(maxTable);
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
        private void AddContent(Document document, bool wrapImages, int imageWidthProperty, UnitValue imageWidth,
                                int divWidthProperty, UnitValue divWidth, ClearPropertyValue?clearValue, int firstImage, int lastImage
                                )
        {
            FloatExampleTest.ImageProperties[] images = new FloatExampleTest.ImageProperties[4];
            images[0] = new FloatExampleTest.ImageProperties(this, FloatPropertyValue.NONE, clearValue, HorizontalAlignment
                                                             .CENTER);
            images[1] = new FloatExampleTest.ImageProperties(this, FloatPropertyValue.RIGHT, clearValue, HorizontalAlignment
                                                             .CENTER);
            images[2] = new FloatExampleTest.ImageProperties(this, FloatPropertyValue.LEFT, clearValue, HorizontalAlignment
                                                             .CENTER);
            images[3] = new FloatExampleTest.ImageProperties(this, FloatPropertyValue.NONE, clearValue, HorizontalAlignment
                                                             .CENTER);
            Paragraph paragraph = new Paragraph().Add("Four images followed by two paragraphs.\n");

            if (wrapImages)
            {
                String s = "Each image is wrapped in a div.\n";
                s += "All divs specify CLEAR = " + clearValue;
                if (divWidthProperty > 0)
                {
                    s += ", " + ((divWidthProperty == Property.WIDTH) ? "WIDTH" : "MAX_WIDTH") + "= " + divWidth;
                }
                if (imageWidthProperty > 0)
                {
                    s += ".\nAll images specify " + ((imageWidthProperty == Property.WIDTH) ? "WIDTH" : "MAX_WIDTH") + " = " +
                         imageWidth;
                }
                paragraph.Add(s + ".\n");
            }
            else
            {
                String s = "All images specify CLEAR = " + clearValue;
                if (imageWidthProperty > 0)
                {
                    s += ", " + ((imageWidthProperty == Property.WIDTH) ? "WIDTH" : "MAX_WIDTH") + "= " + imageWidth;
                }
                paragraph.Add(s + ".\n");
            }
            for (int i = firstImage; i <= lastImage; i++)
            {
                paragraph.Add((wrapImages ? "Div" : "Image") + " " + (i) + ": " + images[i] + "\n");
            }
            document.Add(paragraph);
            for (int i = firstImage; i <= lastImage; i++)
            {
                int pictNumber = i + 1;
                iText.Layout.Element.Image image = new Image(ImageDataFactory.Create(sourceFolder + pictNumber + ".png")).
                                                   SetBorder(new SolidBorder(imageBorderColor, IMAGE_BORDER_WIDTH)).SetHorizontalAlignment(images[i].horizontalAlignment
                                                                                                                                           );
                if (wrapImages)
                {
                    Div div = new Div().SetBorder(new SolidBorder(DIV_BORDER_WIDTH)).SetMargins(BORDER_MARGIN, 0, BORDER_MARGIN
                                                                                                , BORDER_MARGIN);
                    div.SetHorizontalAlignment(images[i].horizontalAlignment);
                    div.SetProperty(Property.CLEAR, images[i].clearPropertyValue);
                    div.SetProperty(Property.FLOAT, images[i].floatPropertyValue);
                    if (divWidthProperty > 0)
                    {
                        div.SetProperty(divWidthProperty, divWidth);
                    }
                    if (imageWidthProperty > 0)
                    {
                        image.SetProperty(imageWidthProperty, imageWidth);
                    }
                    div.Add(image);
                    div.Add(new Paragraph("Figure for Div" + i + ": This is longer text that wraps This is longer text that wraps"
                                          ).SetTextAlignment(TextAlignment.CENTER)).SetBold();
                    document.Add(div);
                }
                else
                {
                    image.SetMargins(BORDER_MARGIN, 0, BORDER_MARGIN, BORDER_MARGIN);
                    image.SetProperty(Property.CLEAR, images[i].clearPropertyValue);
                    image.SetProperty(Property.FLOAT, images[i].floatPropertyValue);
                    if (imageWidthProperty > 0)
                    {
                        image.SetProperty(imageWidthProperty, imageWidth);
                    }
                    document.Add(image);
                }
            }
            document.Add(new Paragraph("The following outline is provided as an over-view of and topical guide to Zambia:"
                                       ));
            document.Add(new Paragraph("Zambia – landlocked sovereign country located in Southern Africa.[1] Zambia has been inhabited for thousands of years by hunter-gatherers and migrating tribes. After sporadic visits by European explorers starting in the 18th century, Zambia was gradually claimed and occupied by the British as protectorate of Northern Rhodesia towards the end of the nineteenth century. On 24 October 1964, the protectorate gained independence with the new name of Zambia, derived from the Zam-bezi river which flows through the country. After independence the country moved towards a system of one party rule with Kenneth Kaunda as president. Kaunda dominated Zambian politics until multiparty elections were held in 1991."
                                       ));
        }
Exemple #28
0
        public void Section_with_a_margin()
        {
            //Arrange
            var margin = new UnitRectangle {
                Top = UnitValue.Parse("1cm"), Left = UnitValue.Parse("2px"), Bottom = UnitValue.Parse("30mm"), Right = UnitValue.Parse("4cm")
            };
            var section = new Section
            {
                Margin = margin
            };
            var template = new Template(section);
            var xml      = template.ToXml();

            //Act
            var otherTemplate = Template.Load(xml);

            //Assert
            Assert.AreEqual(xml.OuterXml, otherTemplate.ToXml().OuterXml);
            Assert.AreEqual(margin.Left, otherTemplate.SectionList.First().Margin.Left);
            Assert.AreEqual(margin.Top, otherTemplate.SectionList.First().Margin.Top);
            Assert.AreEqual(margin.Right, otherTemplate.SectionList.First().Margin.Right);
            Assert.AreEqual(margin.Bottom, otherTemplate.SectionList.First().Margin.Bottom);
            Assert.AreEqual(margin.Width, otherTemplate.SectionList.First().Margin.Width);
            Assert.AreEqual(margin.Height, otherTemplate.SectionList.First().Margin.Height);
            Assert.AreEqual(margin, otherTemplate.SectionList.First().Margin);
        }
Exemple #29
0
        public virtual void LargeEmptyTableTest02()
        {
            String      testName    = "largeEmptyTableTest02.pdf";
            String      outFileName = destinationFolder + testName;
            String      cmpFileName = sourceFolder + "cmp_" + testName;
            PdfDocument pdfDoc      = new PdfDocument(new PdfWriter(outFileName));
            Document    doc         = new Document(pdfDoc, PageSize.A4.Rotate());
            Table       table       = new Table(UnitValue.CreatePercentArray(3), true);

            doc.Add(table);
            for (int i = 0; i < 3; i++)
            {
                table.AddHeaderCell(new Cell().Add(new Paragraph("Header" + i)));
            }
            table.Complete();
            doc.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetBorder(new SolidBorder(ColorConstants
                                                                                                                .ORANGE, 2)).AddCell("Is my occupied area correct?"));
            doc.Add(new AreaBreak());
            table = new Table(UnitValue.CreatePercentArray(3), true);
            doc.Add(table);
            for (int i = 0; i < 3; i++)
            {
                table.AddFooterCell(new Cell().Add(new Paragraph("Footer" + i)));
            }
            table.Complete();
            doc.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetBorder(new SolidBorder(ColorConstants
                                                                                                                .ORANGE, 2)).AddCell("Is my occupied area correct?"));
            doc.Add(new AreaBreak());
            table = new Table(UnitValue.CreatePercentArray(3), true);
            doc.Add(table);
            for (int i = 0; i < 3; i++)
            {
                table.AddHeaderCell(new Cell().Add(new Paragraph("Header" + i)));
                table.AddFooterCell(new Cell().Add(new Paragraph("Footer" + i)));
            }
            table.Complete();
            doc.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetBorder(new SolidBorder(ColorConstants
                                                                                                                .ORANGE, 2)).AddCell("Is my occupied area correct?"));
            doc.Add(new AreaBreak());
            table = new Table(UnitValue.CreatePercentArray(3), true);
            doc.Add(table);
            for (int i = 0; i < 3; i++)
            {
                table.AddHeaderCell(new Cell().Add(new Paragraph("Header" + i)));
                table.AddFooterCell(new Cell().Add(new Paragraph("Footer" + i)));
            }
            table.AddCell(new Cell().Add(new Paragraph("Cell")));
            table.Complete();
            doc.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetBorder(new SolidBorder(ColorConstants
                                                                                                                .ORANGE, 2)).AddCell("Is my occupied area correct?"));
            doc.Add(new AreaBreak());
            table = new Table(UnitValue.CreatePercentArray(3), true);
            doc.Add(table);
            for (int i = 0; i < 2; i++)
            {
                table.AddHeaderCell(new Cell().Add(new Paragraph("Header" + i)));
                table.AddFooterCell(new Cell().Add(new Paragraph("Footer" + i)));
            }
            table.Complete();
            doc.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetBorder(new SolidBorder(ColorConstants
                                                                                                                .ORANGE, 2)).AddCell("Is my occupied area correct?"));
            doc.Add(new AreaBreak());
            table = new Table(UnitValue.CreatePercentArray(3), true);
            doc.Add(table);
            for (int i = 0; i < 2; i++)
            {
                table.AddHeaderCell(new Cell().Add(new Paragraph("Header" + i)));
                table.AddFooterCell(new Cell().Add(new Paragraph("Footer" + i)));
            }
            table.AddCell(new Cell().Add(new Paragraph("Cell")));
            table.Complete();
            doc.Add(new Table(UnitValue.CreatePercentArray(1)).UseAllAvailableWidth().SetBorder(new SolidBorder(ColorConstants
                                                                                                                .ORANGE, 2)).AddCell("Is my occupied area correct?"));
            doc.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , testName + "_diff"));
        }
Exemple #30
0
 public void UnparsableUnitValueThrowsFormatException(string str)
 {
     Assert.That(() => UnitValue.Parse(str), Throws.TypeOf <FormatException>());
 }
Exemple #31
0
        public override LayoutResult Layout(LayoutContext layoutContext)
        {
            LayoutArea      area         = layoutContext.GetArea().Clone();
            Rectangle       layoutBox    = area.GetBBox().Clone();
            AffineTransform t            = new AffineTransform();
            Image           modelElement = (Image)(GetModelElement());
            PdfXObject      xObject      = modelElement.GetXObject();

            imageWidth  = modelElement.GetImageWidth();
            imageHeight = modelElement.GetImageHeight();
            CalculateImageDimensions(layoutBox, t, xObject);
            OverflowPropertyValue?overflowX = null != parent?parent.GetProperty <OverflowPropertyValue?>(Property.OVERFLOW_X
                                                                                                         ) : OverflowPropertyValue.FIT;

            bool nowrap = false;

            if (parent is LineRenderer)
            {
                nowrap = true.Equals(this.parent.GetOwnProperty <bool?>(Property.NO_SOFT_WRAP_INLINE));
            }
            IList <Rectangle> floatRendererAreas    = layoutContext.GetFloatRendererAreas();
            float             clearHeightCorrection = FloatingHelper.CalculateClearHeightCorrection(this, floatRendererAreas, layoutBox
                                                                                                    );
            FloatPropertyValue?floatPropertyValue = this.GetProperty <FloatPropertyValue?>(Property.FLOAT);

            if (FloatingHelper.IsRendererFloating(this, floatPropertyValue))
            {
                layoutBox.DecreaseHeight(clearHeightCorrection);
                FloatingHelper.AdjustFloatedBlockLayoutBox(this, layoutBox, width, floatRendererAreas, floatPropertyValue,
                                                           overflowX);
            }
            else
            {
                clearHeightCorrection = FloatingHelper.AdjustLayoutBoxAccordingToFloats(floatRendererAreas, layoutBox, width
                                                                                        , clearHeightCorrection, null);
            }
            ApplyMargins(layoutBox, false);
            Border[] borders = GetBorders();
            ApplyBorderBox(layoutBox, borders, false);
            float?declaredMaxHeight         = RetrieveMaxHeight();
            OverflowPropertyValue?overflowY = null == parent || ((null == declaredMaxHeight || declaredMaxHeight > layoutBox
                                                                  .GetHeight()) && !layoutContext.IsClippedHeight()) ? OverflowPropertyValue.FIT : parent.GetProperty <OverflowPropertyValue?
                                                                                                                                                                       >(Property.OVERFLOW_Y);
            bool processOverflowX = !IsOverflowFit(overflowX) || nowrap;
            bool processOverflowY = !IsOverflowFit(overflowY);

            if (IsAbsolutePosition())
            {
                ApplyAbsolutePosition(layoutBox);
            }
            occupiedArea = new LayoutArea(area.GetPageNumber(), new Rectangle(layoutBox.GetX(), layoutBox.GetY() + layoutBox
                                                                              .GetHeight(), 0, 0));
            float imageContainerWidth  = (float)width;
            float imageContainerHeight = (float)height;

            if (IsFixedLayout())
            {
                fixedXPosition = this.GetPropertyAsFloat(Property.LEFT);
                fixedYPosition = this.GetPropertyAsFloat(Property.BOTTOM);
            }
            float?angle = this.GetPropertyAsFloat(Property.ROTATION_ANGLE);

            // See in adjustPositionAfterRotation why angle = 0 is necessary
            if (null == angle)
            {
                angle = 0f;
            }
            t.Rotate((float)angle);
            initialOccupiedAreaBBox = GetOccupiedAreaBBox().Clone();
            float scaleCoef = AdjustPositionAfterRotation((float)angle, layoutBox.GetWidth(), layoutBox.GetHeight());

            imageContainerHeight *= scaleCoef;
            imageContainerWidth  *= scaleCoef;
            initialOccupiedAreaBBox.MoveDown(imageContainerHeight);
            initialOccupiedAreaBBox.SetHeight(imageContainerHeight);
            initialOccupiedAreaBBox.SetWidth(imageContainerWidth);
            if (xObject is PdfFormXObject)
            {
                t.Scale(scaleCoef, scaleCoef);
            }
            float imageItselfWidth;
            float imageItselfHeight;

            ApplyObjectFit(modelElement.GetObjectFit(), imageWidth, imageHeight);
            if (modelElement.GetObjectFit() == ObjectFit.FILL)
            {
                imageItselfWidth  = imageContainerWidth;
                imageItselfHeight = imageContainerHeight;
            }
            else
            {
                imageItselfWidth  = renderedImageWidth;
                imageItselfHeight = renderedImageHeight;
            }
            GetMatrix(t, imageItselfWidth, imageItselfHeight);
            // indicates whether the placement is forced
            bool isPlacingForced = false;

            if (width > layoutBox.GetWidth() || height > layoutBox.GetHeight())
            {
                if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT)) || (width > layoutBox.GetWidth() && processOverflowX
                                                                                     ) || (height > layoutBox.GetHeight() && processOverflowY))
                {
                    isPlacingForced = true;
                }
                else
                {
                    ApplyMargins(initialOccupiedAreaBBox, true);
                    ApplyBorderBox(initialOccupiedAreaBBox, true);
                    occupiedArea.GetBBox().SetHeight(initialOccupiedAreaBBox.GetHeight());
                    return(new MinMaxWidthLayoutResult(LayoutResult.NOTHING, occupiedArea, null, this, this));
                }
            }
            occupiedArea.GetBBox().MoveDown((float)height);
            if (borders[3] != null)
            {
                float delta         = (float)Math.Sin((float)angle) * borders[3].GetWidth();
                float renderScaling = renderedImageHeight / (float)height;
                height += delta;
                renderedImageHeight += delta * renderScaling;
            }
            occupiedArea.GetBBox().SetHeight((float)height);
            occupiedArea.GetBBox().SetWidth((float)width);
            UnitValue leftMargin = this.GetPropertyAsUnitValue(Property.MARGIN_LEFT);

            if (!leftMargin.IsPointValue())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ImageRenderer));
                logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                      .MARGIN_LEFT));
            }
            UnitValue topMargin = this.GetPropertyAsUnitValue(Property.MARGIN_TOP);

            if (!topMargin.IsPointValue())
            {
                ILog logger = LogManager.GetLogger(typeof(iText.Layout.Renderer.ImageRenderer));
                logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property
                                                      .MARGIN_TOP));
            }
            if (0 != leftMargin.GetValue() || 0 != topMargin.GetValue())
            {
                TranslateImage(leftMargin.GetValue(), topMargin.GetValue(), t);
                GetMatrix(t, imageContainerWidth, imageContainerHeight);
            }
            ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
            ApplyMargins(occupiedArea.GetBBox(), true);
            if (angle != 0)
            {
                ApplyRotationLayout((float)angle);
            }
            float       unscaledWidth = occupiedArea.GetBBox().GetWidth() / scaleCoef;
            MinMaxWidth minMaxWidth   = new MinMaxWidth(unscaledWidth, unscaledWidth, 0);
            UnitValue   rendererWidth = this.GetProperty <UnitValue>(Property.WIDTH);

            if (rendererWidth != null && rendererWidth.IsPercentValue())
            {
                minMaxWidth.SetChildrenMinWidth(0);
                float coeff = imageWidth / (float)RetrieveWidth(area.GetBBox().GetWidth());
                minMaxWidth.SetChildrenMaxWidth(unscaledWidth * coeff);
            }
            else
            {
                bool autoScale      = HasProperty(Property.AUTO_SCALE) && (bool)this.GetProperty <bool?>(Property.AUTO_SCALE);
                bool autoScaleWidth = HasProperty(Property.AUTO_SCALE_WIDTH) && (bool)this.GetProperty <bool?>(Property.AUTO_SCALE_WIDTH
                                                                                                               );
                if (autoScale || autoScaleWidth)
                {
                    minMaxWidth.SetChildrenMinWidth(0);
                }
            }
            FloatingHelper.RemoveFloatsAboveRendererBottom(floatRendererAreas, this);
            LayoutArea editedArea = FloatingHelper.AdjustResultOccupiedAreaForFloatAndClear(this, floatRendererAreas,
                                                                                            layoutContext.GetArea().GetBBox(), clearHeightCorrection, false);

            ApplyAbsolutePositionIfNeeded(layoutContext);
            return(new MinMaxWidthLayoutResult(LayoutResult.FULL, editedArea, null, null, isPlacingForced ? this : null
                                               ).SetMinMaxWidth(minMaxWidth));
        }
Exemple #32
0
        internal override void Render(IRenderData renderData, int page)
        {
            if (IsNotVisible(renderData))
            {
                return;
            }

            var pushTextForwardOnPages = 0;

            if (Visibility == PageVisibility.LastPage && renderData.PageNumberInfo.TotalPages != page)
            {
                pushTextForwardOnPages = renderData.PageNumberInfo.TotalPages.Value - 1;
            }

            if (_pageRowSet == null)
            {
                throw new InvalidOperationException("PreRendering has not yet been performed.");
            }

            renderData.ElementBounds = GetBounds(renderData.ParentBounds);

            if (!renderData.IncludeBackground && IsBackground)
            {
                return;
            }

            var headerFont  = new XFont(_headerFont.GetName(renderData.Section), _headerFont.GetSize(renderData.Section), _headerFont.GetStyle(renderData.Section));
            var headerBrush = new XSolidBrush(XColor.FromArgb(_headerFont.GetColor(renderData.Section)));
            var lineFont    = new XFont(_contentFont.GetName(renderData.Section), _contentFont.GetSize(renderData.Section), _contentFont.GetStyle(renderData.Section));
            var lineBrush   = new XSolidBrush(XColor.FromArgb(_contentFont.GetColor(renderData.Section)));
            var groupFont   = new XFont(_groupFont.GetName(renderData.Section), _groupFont.GetSize(renderData.Section), _groupFont.GetStyle(renderData.Section));

            var firstColumn = _columns.FirstOrDefault();

            if (firstColumn.Value == null)
            {
                return;
            }
            var headerSize  = renderData.Graphics.MeasureString(firstColumn.Value.Title, headerFont, XStringFormats.TopLeft);
            var stdLineSize = renderData.Graphics.MeasureString(firstColumn.Value.Title, lineFont, XStringFormats.TopLeft);

            if (renderData.DebugData != null)
            {
                renderData.Graphics.DrawString(string.Format("Table: {0}", Name), renderData.DebugData.Font, renderData.DebugData.Brush, renderData.ElementBounds.Center);
            }

            if (renderData.DocumentData != null)
            {
                var dataTable = renderData.DocumentData.GetDataTable(Name);
                if (dataTable != null)
                {
                    var columnPadding = ColumnPadding.ToXUnit(renderData.ElementBounds.Width);

                    foreach (var column in _columns.Where(x => x.Value.WidthMode == WidthMode.Auto).ToList())
                    {
                        //Get the size of the columnt title text
                        var stringSize = renderData.Graphics.MeasureString(column.Value.Title, headerFont, XStringFormats.TopLeft);
                        var wd         = UnitValue.Parse((stringSize.Width + columnPadding).ToString(CultureInfo.InvariantCulture) + "px");

                        //If there is a fixed width value, start with that.
                        if (column.Value.Width == null)
                        {
                            column.Value.Width = wd;
                        }

                        //If the column header title is greater than
                        if (column.Value.Width.Value < wd)
                        {
                            column.Value.Width = wd;
                        }

                        foreach (var row in dataTable.Rows)
                        {
                            if (row is DocumentDataTableData)
                            {
                                var rowData = row as DocumentDataTableData;

                                var cellData = GetValue(column.Key, rowData.Columns);
                                stringSize = renderData.Graphics.MeasureString(cellData, lineFont, XStringFormats.TopLeft);
                                wd         = UnitValue.Parse((stringSize.Width + columnPadding).ToString(CultureInfo.InvariantCulture) + "px");
                                if (column.Value.Width < wd)
                                {
                                    column.Value.Width = wd;
                                }
                            }
                        }
                    }

                    foreach (var column in _columns.ToList())
                    {
                        if (column.Value.HideValue != null)
                        {
                            column.Value.Hide = true;
                        }

                        foreach (var row in dataTable.Rows)
                        {
                            if (row is DocumentDataTableData)
                            {
                                var rowData         = row as DocumentDataTableData;
                                var cellData        = GetValue(column.Key, rowData.Columns);
                                var parsedHideValue = GetValue(column.Value.HideValue, rowData.Columns);
                                if (parsedHideValue != cellData)
                                {
                                    column.Value.Hide = false;
                                }
                            }
                        }

                        if (column.Value.Hide)
                        {
                            column.Value.Width = new UnitValue();
                            if (HideTableWhenColumnIsHidden == column.Key)
                            {
                                //Hide the entire table
                                return;
                            }
                        }
                    }

                    RenderBorder(renderData.ElementBounds, renderData.Graphics, headerSize);

                    var totalWidth     = renderData.ElementBounds.Width;
                    var nonSpringWidth = _columns.Where(x => x.Value.WidthMode != WidthMode.Spring).Sum(x => x.Value.Width != null ? x.Value.Width.Value.ToXUnit(totalWidth) : 0);

                    var springCount = _columns.Count(x => x.Value.WidthMode == WidthMode.Spring && !x.Value.Hide);
                    if (springCount > 0)
                    {
                        foreach (var column in _columns.Where(x => x.Value.WidthMode == WidthMode.Spring && !x.Value.Hide).ToList())
                        {
                            if (column.Value.Width == null)
                            {
                                column.Value.Width = "0";
                            }
                            var calculatedWidth = new UnitValue((renderData.ElementBounds.Width - nonSpringWidth) / springCount, UnitValue.EUnit.Point);
                            if (calculatedWidth > column.Value.Width)
                            {
                                column.Value.Width = calculatedWidth;
                            }
                        }
                    }

                    AssureTotalColumnWidth(renderData.ElementBounds.Width);

                    //Create header
                    double left         = 0;
                    var    tableColumns = _columns.Values.Where(x => !x.Hide).ToList();
                    foreach (var column in tableColumns)
                    {
                        var alignmentJusttification = 0D;
                        if (column.Align == Alignment.Right)
                        {
                            var stringSize = renderData.Graphics.MeasureString(column.Title, headerFont, XStringFormats.TopLeft);
                            alignmentJusttification = column.Width.Value.ToXUnit(renderData.ElementBounds.Width) - stringSize.Width - (columnPadding / 2);
                        }
                        else
                        {
                            alignmentJusttification += columnPadding / 2;
                        }

                        renderData.Graphics.DrawString(column.Title, headerFont, headerBrush, new XPoint(renderData.ElementBounds.Left + left + alignmentJusttification, renderData.ElementBounds.Top), XStringFormats.TopLeft);
                        left += column.Width.Value.ToXUnit(renderData.ElementBounds.Width);

                        if (renderData.DebugData != null)
                        {
                            renderData.Graphics.DrawLine(renderData.DebugData.Pen, renderData.ElementBounds.Left + left, renderData.ElementBounds.Top, renderData.ElementBounds.Left + left, renderData.ElementBounds.Bottom);
                        }
                    }

                    var top       = headerSize.Height + RowPadding.ToXUnit(renderData.ElementBounds.Height);
                    var pageIndex = 1;

                    var defaultRowset = true;
                    var pageRowSet    = new PageRowSet {
                        FromRow = 1
                    };
                    var index = page - renderData.Section.GetPageOffset() - pushTextForwardOnPages;
                    if (_pageRowSet.Count > index)
                    {
                        try
                        {
                            defaultRowset = false;
                            pageRowSet    = _pageRowSet[index];
                        }
                        catch (Exception exception)
                        {
                            throw new InvalidOperationException(string.Format("_pageRowSet.Count={0}, index={1}", _pageRowSet.Count, index), exception);
                        }
                    }

                    //Draw column separator lines
                    if (ColumnBorderColor != null)
                    {
                        left = 0;
                        var borderPen = new XPen(ColumnBorderColor.Value, 0.1); //TODO: Set the thickness of the boarder
                        foreach (var column in _columns.Where(x => !x.Value.Hide).TakeAllButLast().ToList())
                        {
                            left += column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width);
                            renderData.Graphics.DrawLine(borderPen, renderData.ElementBounds.Left + left, renderData.ElementBounds.Top, renderData.ElementBounds.Left + left, renderData.ElementBounds.Bottom);
                        }
                    }

                    for (var i = pageRowSet.FromRow; i < pageRowSet.ToRow + 1; i++)
                    {
                        DocumentDataTableLine row;
                        try
                        {
                            row = dataTable.Rows[i];
                        }
                        catch (Exception exception)
                        {
                            var msg = string.Format("Looping from {0} to {1}. Currently at {2}, collection has {3} lines.", pageRowSet.FromRow, pageRowSet.ToRow + 1, i, dataTable.Rows.Count);
                            throw new InvalidOperationException(msg + string.Format("dataTable.Rows.Count={0}, i={1}, pageIndex={2}, page={3}, GetPageOffset={4}, index={5}, FromRow={6}, ToRow={7}, _pageRowSet.Count={8}, defaultRowset={9}", dataTable.Rows.Count, i, pageIndex, page, renderData.Section.GetPageOffset(), index, pageRowSet.FromRow, pageRowSet.ToRow, _pageRowSet.Count, defaultRowset), exception);
                        }

                        left = 0;
                        var lineSize = stdLineSize;
                        if (row is DocumentDataTableData)
                        {
                            var rowData = row as DocumentDataTableData;

                            foreach (var column in _columns.Where(x => !x.Value.Hide).ToList())
                            {
                                var cellData = GetValue(column.Key, rowData.Columns);

                                var alignmentJusttification = 0D;
                                if (column.Value.Align == Alignment.Right)
                                {
                                    var stringSize = renderData.Graphics.MeasureString(cellData, lineFont, XStringFormats.TopLeft);
                                    alignmentJusttification = column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width) - stringSize.Width - (columnPadding / 2);
                                }
                                else
                                {
                                    alignmentJusttification += columnPadding / 2;
                                }

                                var parsedHideValue = GetValue(column.Value.HideValue, rowData.Columns);
                                if (parsedHideValue == cellData)
                                {
                                    cellData = string.Empty;
                                }

                                //TODO: If the string is too long. Cut the string down.
                                var calculatedCellData = AssureThatTextFitsInColumn(renderData, cellData, column, columnPadding, lineFont);

                                renderData.Graphics.DrawString(calculatedCellData, lineFont, lineBrush, new XPoint(renderData.ElementBounds.Left + left + alignmentJusttification, renderData.ElementBounds.Top + top), XStringFormats.TopLeft);
                                left += column.Value.Width.Value.ToXUnit(renderData.ElementBounds.Width);
                            }

                            if (_skipLine != null && pageIndex % SkipLine.Interval == 0)
                            {
                                var skipLineHeight = SkipLine.Height.ToXUnit(renderData.ElementBounds.Height);

                                if (SkipLine.BorderColor != null)
                                {
                                    renderData.Graphics.DrawLine(new XPen(XColor.FromArgb((Color)SkipLine.BorderColor), 0.1), renderData.ElementBounds.Left, renderData.ElementBounds.Top + top + lineSize.Height + skipLineHeight / 2, renderData.ElementBounds.Right, renderData.ElementBounds.Top + top + lineSize.Height + skipLineHeight / 2);
                                }

                                top += skipLineHeight;
                            }
                        }
                        else if (row is DocumentDataTableGroup)
                        {
                            var group = row as DocumentDataTableGroup;

                            if (pageIndex != 1)
                            {
                                top += GroupSpacing.ToXUnit(renderData.ElementBounds.Height);
                            }

                            var groupData  = group.Content;
                            var stringSize = renderData.Graphics.MeasureString(groupData, groupFont, XStringFormats.TopLeft);
                            lineSize = stringSize;
                            var topLeftBox  = new XPoint(renderData.ElementBounds.Left + left, renderData.ElementBounds.Top + top);
                            var topLeftText = new XPoint(renderData.ElementBounds.Left + left + (columnPadding / 2), renderData.ElementBounds.Top + top);

                            if (GroupBackgroundColor != null)
                            {
                                var brush = new XSolidBrush(XColor.FromArgb(GroupBackgroundColor.Value));
                                var rect  = new XRect(topLeftBox, new XSize(renderData.ElementBounds.Width, stringSize.Height));
                                renderData.Graphics.DrawRectangle(new XPen(XColor.FromArgb(GroupBorderColor ?? GroupBackgroundColor.Value), 0.1), brush, rect);
                            }
                            else if (GroupBorderColor != null)
                            {
                                var rect = new XRect(topLeftBox, new XSize(renderData.ElementBounds.Width, stringSize.Height));
                                renderData.Graphics.DrawRectangle(new XPen(XColor.FromArgb(GroupBorderColor.Value), 0.1), rect);
                            }

                            renderData.Graphics.DrawString(groupData, groupFont, lineBrush, topLeftText, XStringFormats.TopLeft);
                            pageIndex = 0;
                        }

                        top += lineSize.Height;
                        top += RowPadding.ToXUnit(renderData.ElementBounds.Height);

                        pageIndex++;
                    }

                    ////Draw column separator lines
                    //if (ColumnBorderColor != null)
                    //{
                    //    left = 0;
                    //    var borderPen = new XPen(ColumnBorderColor.Value, 0.1); //TODO: Set the thickness of the boarder
                    //    foreach (var column in _columns.Where(x => !x.Value.Hide).TakeAllButLast().ToList())
                    //    {
                    //        left += column.Value.Width.Value.GetXUnitValue(renderData.ElementBounds.Width);
                    //        renderData.Graphics.DrawLine(borderPen, renderData.ElementBounds.Left + left, renderData.ElementBounds.Top, renderData.ElementBounds.Left + left, renderData.ElementBounds.Bottom);
                    //    }
                    //}
                }
            }

            if (renderData.DebugData != null)
            {
                renderData.Graphics.DrawRectangle(renderData.DebugData.Pen, renderData.ElementBounds);
            }
        }
        /// <summary>
        /// Creates a
        /// <see cref="iText.Layout.Borders.Border"/>
        /// instance based on specific properties.
        /// </summary>
        /// <param name="borderWidth">the border width</param>
        /// <param name="borderStyle">the border style</param>
        /// <param name="borderColor">the border color</param>
        /// <param name="em">the em value</param>
        /// <param name="rem">the root em value</param>
        /// <returns>the border</returns>
        public static Border GetCertainBorder(String borderWidth, String borderStyle, String borderColor, float em
                                              , float rem)
        {
            if (borderStyle == null || CssConstants.NONE.Equals(borderStyle))
            {
                return(null);
            }
            if (borderWidth == null)
            {
                borderWidth = CssDefaults.GetDefaultValue(CssConstants.BORDER_WIDTH);
            }
            float borderWidthValue;

            if (CssConstants.BORDER_WIDTH_VALUES.Contains(borderWidth))
            {
                if (CssConstants.THIN.Equals(borderWidth))
                {
                    borderWidth = "1px";
                }
                else
                {
                    if (CssConstants.MEDIUM.Equals(borderWidth))
                    {
                        borderWidth = "2px";
                    }
                    else
                    {
                        if (CssConstants.THICK.Equals(borderWidth))
                        {
                            borderWidth = "3px";
                        }
                    }
                }
            }
            UnitValue unitValue = CssDimensionParsingUtils.ParseLengthValueToPt(borderWidth, em, rem);

            if (unitValue == null)
            {
                return(null);
            }
            if (unitValue.IsPercentValue())
            {
                return(null);
            }
            borderWidthValue = unitValue.GetValue();
            Border border = null;

            if (borderWidthValue > 0)
            {
                DeviceRgb color   = (DeviceRgb)ColorConstants.BLACK;
                float     opacity = 1f;
                if (borderColor != null)
                {
                    if (!CssConstants.TRANSPARENT.Equals(borderColor))
                    {
                        float[] rgbaColor = CssDimensionParsingUtils.ParseRgbaColor(borderColor);
                        color   = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
                        opacity = rgbaColor[3];
                    }
                    else
                    {
                        opacity = 0f;
                    }
                }
                else
                {
                    if (CssConstants.GROOVE.Equals(borderStyle) || CssConstants.RIDGE.Equals(borderStyle) || CssConstants.INSET
                        .Equals(borderStyle) || CssConstants.OUTSET.Equals(borderStyle))
                    {
                        color = new DeviceRgb(212, 208, 200);
                    }
                }
                switch (borderStyle)
                {
                case CssConstants.SOLID: {
                    border = new SolidBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.DASHED: {
                    border = new DashedBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.DOTTED: {
                    border = new RoundDotsBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.DOUBLE: {
                    border = new DoubleBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.GROOVE: {
                    border = new GrooveBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.RIDGE: {
                    border = new RidgeBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.INSET: {
                    border = new InsetBorder(color, borderWidthValue, opacity);
                    break;
                }

                case CssConstants.OUTSET: {
                    border = new OutsetBorder(color, borderWidthValue, opacity);
                    break;
                }

                default: {
                    border = null;
                    break;
                }
                }
            }
            return(border);
        }
Exemple #34
0
 /// <summary>
 /// Sets the width property of the element with a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// .
 /// </summary>
 /// <param name="width">
 /// a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// object
 /// </param>
 /// <returns>this Element.</returns>
 public virtual Style SetWidth(UnitValue width)
 {
     SetProperty(Property.WIDTH, width);
     return((Style)(Object)this);
 }
Exemple #35
0
        public PdfManager GenerateLeadsReport()
        {
            LeadService _leadService    = new LeadService();
            FileInfo    file            = new FileInfo(pdfDestination);
            var         fontDestination = System.IO.Path.Combine(targetFolder, "times.ttf");

            //document settings
            pdfDoc = new PdfDocument(new PdfWriter(pdfDestination));
            pdfDoc.SetDefaultPageSize(PageSize.A4);
            document = new Document(pdfDoc, PageSize.A4, false).SetFontSize(12);
            //set header
            PdfFont font = PdfFontFactory.CreateFont(fontDestination, PdfEncodings.IDENTITY_H, true);
            PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);

            Paragraph docHeader = new Paragraph("Potential Customers (Leads) Report").SetTextAlignment(TextAlignment.CENTER)
                                  .SetFontSize(headerFontSize).SetFont(bold);
            //set logo
            Image logo = new Image(ImageDataFactory
                                   .Create(logoFile))
                         .SetTextAlignment(TextAlignment.LEFT).SetHeight(60).SetWidth(60);

            document.Add(logo);
            document.Add(docHeader);

            var   currentItem = 1;
            Table table       = new Table(UnitValue.CreatePercentArray(7), false).SetFont(font);

            table.SetWidth(UnitValue.CreatePercentValue(100));
            table.SetFixedLayout();

            Cell c11 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("No."));
            Cell c12 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("Lead's name"));
            Cell c13 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("Company"));
            Cell c14 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("Email Address"));
            Cell c15 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("Phone Number"));
            Cell c16 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("Lead Owner"));
            Cell c17 = new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).SetTextRenderingMode(PdfCanvasConstants.TextRenderingMode.FILL_STROKE).SetStrokeWidth(0.3f).SetStrokeColor(DeviceGray.BLACK).Add(new Paragraph("Source"));

            table.AddHeaderCell(c11);
            table.AddHeaderCell(c12);
            table.AddHeaderCell(c13);
            table.AddHeaderCell(c14);
            table.AddHeaderCell(c15);
            table.AddHeaderCell(c16);
            table.AddHeaderCell(c17);

            var leadList = _leadService.GetLeadList(pageSize: 99999, currentPage: 1, sort: new List <string> {
                "asc.name"
            });

            foreach (var lead in leadList.leads)
            {
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(currentItem.ToString())));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(lead.name ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(lead.companyName ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(lead.email ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(lead.phone ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(lead.leadOwner ?? "")));
                table.AddCell(new Cell(1, 1).SetTextAlignment(TextAlignment.CENTER).SetFontSize(fontSize).Add(new Paragraph(lead.leadSource ?? "")));
                currentItem++;
            }

            document.Add(table);

            document.Add(new Paragraph(new Text("\n")));

            var dateSignature = new Paragraph("Hanoi, " + DateTime.Now.ToString("D")).SetTextAlignment(TextAlignment.RIGHT).SetMarginRight(30);

            //.SetFixedPosition(PageSize.A4.GetRight() - 170, PageSize.A4.GetBottom() + 80, 150);
            document.Add(dateSignature);
            document.Add(new Paragraph(new Text("\n\n")));
            document.Add(new Paragraph(new Text("Signature: ________________________")).SetTextAlignment(TextAlignment.RIGHT).SetMarginRight(0));


            int numberOfPages = pdfDoc.GetNumberOfPages();

            for (int i = 1; i <= numberOfPages; i++)
            {
                document.ShowTextAligned(new Paragraph(String
                                                       .Format(i.ToString())),
                                         559, PageSize.A4.GetBottom() + 20, i, TextAlignment.RIGHT,//806
                                         VerticalAlignment.BOTTOM, 0);
            }
            document.Close();
            return(this);
        }
Exemple #36
0
 /// <summary>
 /// Sets the max-height property of the element with a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// .
 /// </summary>
 /// <param name="maxHeight">
 /// a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// object
 /// </param>
 /// <returns>the block element itself</returns>
 public virtual Style SetMaxHeight(UnitValue maxHeight)
 {
     SetProperty(Property.MAX_HEIGHT, maxHeight);
     return((Style)(Object)this);
 }
Exemple #37
0
 /// <summary>Clear all current properties and sets new width and height values.</summary>
 /// <remarks>
 /// Clear all current properties and sets new width and height values.
 /// One of the parameters can be null. Note that in this case CalculationUtil will scale null property
 /// so that it becomes proportionally equals with the not null value.
 /// If both parameters are set to null, that the default image size will be used.
 /// </remarks>
 /// <param name="width">
 /// a
 /// <see cref="UnitValue"/>
 /// object
 /// </param>
 /// <param name="height">
 /// a
 /// <see cref="UnitValue"/>
 /// object
 /// </param>
 /// <seealso cref="com.itextpdf.layout.renderer.BackgroundSizeCalculationUtil#calculateBackgroundImageSize"/>
 public virtual void SetBackgroundSizeToValues(UnitValue width, UnitValue height)
 {
     Clear();
     this.backgroundWidthSize  = width;
     this.backgroundHeightSize = height;
 }
 public static void SetRandomValue(UnitValue uv, decimal increment)
 {
     var rnd = new Random();
     var nr = rnd.Next(1, 500);
     uv.Value = nr*increment;
 }
Exemple #39
0
 /// <summary>Sets the width property of the element, measured in points.</summary>
 /// <param name="width">a value measured in points.</param>
 /// <returns>this Element.</returns>
 public virtual Style SetWidth(float width)
 {
     SetProperty(Property.WIDTH, UnitValue.CreatePointValue(width));
     return((Style)(Object)this);
 }
        public virtual void RelativePositioningTable01Test()
        {
            String      outFileName = destinationFolder + "relativePositioningTable01Test.pdf";
            String      cmpFileName = sourceFolder + "cmp_relativePositioningTable01Test.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
            Document    document    = new Document(pdfDocument);
            Table       table       = new Table(new UnitValue[] { UnitValue.CreatePointValue(100), UnitValue.CreatePointValue(100) });

            table.AddCell("One");
            table.AddCell("Two");
            table.SetRelativePosition(100, 20, 0, 0);
            document.Add(table);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Exemple #41
0
 /// <summary>
 /// Sets the height property of the element with a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// .
 /// </summary>
 /// <param name="height">
 /// a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// object
 /// </param>
 /// <returns>this Element.</returns>
 public virtual Style SetHeight(UnitValue height)
 {
     SetProperty(Property.HEIGHT, height);
     return((Style)(Object)this);
 }
        public string GetValue(string fieldName)
        {
            StringBuilder sb;

            switch (fieldName)
            {
            // fields convertible directly to string:
            case "AtomicNumber":
            case "GroupBlock":
            case "Period":
            case "Category":
            case "ElectronConfiguration":
            case "Phase":
            case "MeltingPoint":
            case "BoilingPoint":
            case "TriplePoint":
            case "CriticalPressure":
            case "CrystalStructure":
            case "MagneticOrdering":
            case "MagneticSusceptibility":
            case "CASNumber":
            case "Discovery":
            // int & double fields:
            case "Electronegativity":
            case "PoissonRatio":
            case "MohsHardness":
            case "AtomicWeight":
            case "StandardAtomicWeight":
                object v = ValueOf(fieldName);
                return((v == null) ? String.Empty : v.ToString());

            // int[]
            case "OxidationStates":
                int[] ii = ValueOf(fieldName) as int[];
                if (ii != null && ii.Length > 0)
                {
                    sb = new StringBuilder();
                    foreach (int i in ii)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(i);
                    }
                    return(sb.ToString());
                }
                break;

            // DValue[]
            case "IonizationEnergies":
                UnitValue[] dvals = ValueOf(fieldName) as UnitValue[];
                if (dvals != null && dvals.Length > 0)
                {
                    return(dvals[0].Units);                             // assume all units same
                }
                break;

            // DValue fields:
            default:
                UnitValue dv = ValueOf(fieldName) as UnitValue;
                return((dv == null) ? String.Empty : dv.ToString());
            }
            return(String.Empty);
        }
Exemple #43
0
 /// <summary>
 /// Sets the min-height property of the element with a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// .
 /// </summary>
 /// <param name="minHeight">
 /// a
 /// <see cref="iText.Layout.Properties.UnitValue"/>
 /// object
 /// </param>
 /// <returns>the block element itself</returns>
 public virtual Style SetMinHeight(UnitValue minHeight)
 {
     SetProperty(Property.MIN_HEIGHT, minHeight);
     return((Style)(Object)this);
 }
Exemple #44
0
        public UnitValue <S, T> Multiply(UnitValue <S, T> unit1, UnitValue <S, T> unit2)
        {
            var result = new UnitValue <S, T>(MultiplyScalar(unit1.Value, unit2.Value), new UnitElement <S, T>(unit1.UnitElement.GetUnitNamePowers().Concat(unit2.UnitElement.GetUnitNamePowers())));

            return(result);
        }
 /// <summary>
 /// Returns the category at a given coordinate.
 /// </summary>
 /// <param name="position">The plot area position.</param>
 /// <returns>The category at the given plot area position.</returns>
 public object GetCategoryAtPosition(UnitValue position)
 {
     if (this.ActualLength == 0.0 || this.Categories.Count == 0)
     {
         return null;
     }
     if (position.Unit == Unit.Pixels)
     {
         double coordinate = position.Value;
         int index = (int)Math.Floor(coordinate / (this.ActualLength / this.Categories.Count));
         if (index >= 0 && index < this.Categories.Count)
         {
             if (Orientation == AxisOrientation.X)
             {
                 return this.Categories[index];
             }
             else
             {
                 return this.Categories[(this.Categories.Count - 1) - index];
             }
         }
     }
     else
     {
         throw new NotImplementedException();
     }
     return null;
 }
Exemple #46
0
        public UnitValue <S, T> Divide(UnitValue <S, T> unit1, UnitValue <S, T> unit2)
        {
            var result = new UnitValue <S, T>(DivideScalar(unit1.Value, unit2.Value), new UnitElement <S, T>(unit1.UnitElement.GetUnitNamePowers().Concat(unit2.UnitElement.GetUnitNamePowers().Select(unp => new UnitNamePower <S, T>(unp.UnitName, -unp.Power)))));

            return(result);
        }
        /// <summary>
        /// Returns the value range given a plot area coordinate.
        /// </summary>
        /// <param name="value">The position.</param>
        /// <returns>A range of values at that plot area coordinate.</returns>
        protected override IComparable GetValueAtPosition(UnitValue value)
        {
            if (ActualRange.HasData && ActualLength != 0.0)
            {
                double coordinate = value.Value;
                if (value.Unit == Unit.Pixels)
                {
                    Range<DateTime> actualDateTimeRange = ToDateTimeRange(ActualRange);

                    double minimumAsDouble = actualDateTimeRange.Minimum.ToOADate();
                    double rangelength = actualDateTimeRange.Maximum.ToOADate() - minimumAsDouble;
                    DateTime output = DateTime.FromOADate((coordinate * (rangelength / ActualLength)) + minimumAsDouble);

                    return output;
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return null;
        }
Exemple #48
0
 public UnitValue <S, T> Substract(UnitValue <S, T> unit1, UnitValue <S, T> unit2)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Returns the value range given a plot area coordinate.
 /// </summary>
 /// <param name="value">The plot area coordinate.</param>
 /// <returns>A range of values at that plot area coordinate.</returns>
 IComparable IRangeAxis.GetValueAtPosition(UnitValue value)
 {
     return GetValueAtPosition(value);
 }
Exemple #50
0
 //private GenPres.Operations.Calculation.PropertyManager pm = GenPres.Operations.Calculation.PropertyManager.Instance;
 internal Factor(UnitValue unitValue)
 {
     _unitValue = unitValue;
 }