Exemplo n.º 1
0
        static void ApplyLocation(PdfStamper stamper, PageNumber pagingOptions, int currrent, int total)
        {
            var font       = pagingOptions.FontOption.Font;
            var text       = pagingOptions.GetText(currrent, total);
            var textPhrase = new Phrase(text, font);
            var textWidth  = font.GetCalculatedBaseFont(true).GetWidthPoint(text, font.Size);
            var pageBox    = stamper.Reader.GetPageSize(currrent);

            switch (pagingOptions.PrintLocation)
            {
            case PageSection.Bottom:
                CreateOnBottom(stamper, pagingOptions, currrent, pageBox, textWidth, textPhrase);
                break;

            case PageSection.Top:
                CreateOnTop(stamper, pagingOptions, currrent, pageBox, textWidth, textPhrase);
                break;

            case PageSection.Left:
                CreateOnLeft(stamper, pagingOptions, currrent, pageBox, textWidth, textPhrase);
                break;

            case PageSection.Right:
                CreateOnRight(stamper, pagingOptions, currrent, pageBox, textWidth, textPhrase);
                break;
            }
        }
Exemplo n.º 2
0
        static void PrintPageNumber(PdfStamper stamper, PageNumber pagingOptions, int currrent, int total)
        {
            float left = 0f, bottom = 0f;

            var font       = pagingOptions.FontOption.Font;
            var text       = pagingOptions.GetText(currrent, total);
            var textPhrase = new Phrase(text, font);
            var textWidth  = font.GetCalculatedBaseFont(true).GetWidthPoint(text, font.Size);
            var pageBox    = stamper.Reader.GetPageSize(currrent);

            if (pagingOptions.Alignment == Alignment.Center && (pagingOptions.PrintLocation == PageSection.Bottom || pagingOptions.PrintLocation == PageSection.Top))
            {
                left = (pageBox.Height + textWidth) / 2;
            }
            if (pagingOptions.Alignment == Alignment.Right && (pagingOptions.PrintLocation == PageSection.Bottom || pagingOptions.PrintLocation == PageSection.Top))
            {
                left = pageBox.Height - textWidth - 15;
            }
            if (pagingOptions.Alignment == Alignment.Left && (pagingOptions.PrintLocation == PageSection.Bottom || pagingOptions.PrintLocation == PageSection.Top))
            {
                left = pageBox.Width - 15;
            }

            if (pagingOptions.Alignment == Alignment.Center && (pagingOptions.PrintLocation == PageSection.Right || pagingOptions.PrintLocation == PageSection.Left))
            {
                bottom = (pageBox.Width + textWidth) / 2;
            }
            if (pagingOptions.Alignment == Alignment.Right && (pagingOptions.PrintLocation == PageSection.Right || pagingOptions.PrintLocation == PageSection.Left))
            {
                bottom = textWidth + 15f;
            }
            if (pagingOptions.Alignment == Alignment.Left && (pagingOptions.PrintLocation == PageSection.Right || pagingOptions.PrintLocation == PageSection.Left))
            {
                bottom = pageBox.Width - textWidth - 15;
            }

            if (pagingOptions.PrintLocation == PageSection.Bottom)
            {
                bottom = 15f;
            }
            if (pagingOptions.PrintLocation == PageSection.Top)
            {
                bottom = pageBox.Width - 15;
            }
            if (pagingOptions.PrintLocation == PageSection.Left)
            {
                left = 15f;
            }
            if (pagingOptions.PrintLocation == PageSection.Right)
            {
                left = pageBox.Height - 15;
            }

            ColumnText.ShowTextAligned(stamper.GetUnderContent(currrent), Element.ALIGN_CENTER, textPhrase, bottom, left, 0,
                                       pagingOptions.Direction == Direction.RightToLeft
                    ? PdfWriter.RUN_DIRECTION_RTL
                    : PdfWriter.RUN_DIRECTION_DEFAULT, 1);
        }