Exemple #1
0
        /// <summary>
        /// Writes the pages numbers
        /// </summary>
        /// <param name="font">Font</param>
        /// <param name="fontSize">Fonr size</param>
        /// <param name="xPt">X position from the bottom in points</param>
        /// <param name="yPt">Y position from the bottom in points</param>
        /// <param name="rgb">RGB color. Blue is the lower byte</param>
        public void WritePagesNumbers(PdfFont font, int fontSize, int xPt, int yPt, int rgb)
        {
            string color     = FormatRGB(rgb);
            int    pageCount = _pages.Count;

            for (int i = 0; i < pageCount; i++)
            {
                PdfPage page     = _pages[i];
                string  txt      = (i + 1) + "/" + pageCount;
                float   txtWidth = font.MesureWidth(txt, fontSize);
                int     xPtAbs   = xPt < 0 ? (int)(xPt + page.Width - txtWidth) : xPt;

                StringBuilder sb = new StringBuilder();
                sb.Append("BT ");
                sb.Append(color + " rg ");
                sb.Append(font.CodeName + " " + fontSize + " Tf ");
                sb.Append(xPtAbs + " " + yPt + " Td\n");
                sb.Append("(" + txt + ")Tj\n");
                sb.Append("ET");

                int id = WriteStreamObject(sb);
                page.AddContent(id);
            }
        }
Exemple #2
0
        /// <summary>
        /// Writes the pages numbers
        /// </summary>
        /// <param name="font">Font</param>
        /// <param name="fontSize">Fonr size</param>
        /// <param name="xPt">X position from the bottom in points</param>
        /// <param name="yPt">Y position from the bottom in points</param>
        /// <param name="rgb">RGB color. Blue is the lower byte</param>
        public void WritePagesNumbers(PdfFont font, int fontSize, int xPt, int yPt, int rgb) {
            string color = FormatRGB(rgb);
            int pageCount = _pages.Count;
            for (int i = 0; i < pageCount; i++) {
                PdfPage page = _pages[i];
                string txt = (i + 1) + "/" + pageCount;
                float txtWidth = font.MesureWidth(txt, fontSize);
                int xPtAbs = xPt < 0 ? (int)(xPt + page.Width - txtWidth) : xPt;

                StringBuilder sb = new StringBuilder();
                sb.Append("BT ");
                sb.Append(color + " rg ");
                sb.Append(font.CodeName + " " + fontSize + " Tf ");
                sb.Append(xPtAbs + " " + yPt + " Td\n");
                sb.Append("(" + txt + ")Tj\n");
                sb.Append("ET");

                int id = WriteStreamObject(sb);
                page.AddContent(id);
            }
        }