public void Default_Numbered_Test()
        {
            Document doc        = new Document();
            int      totalcount = 10;

            //Add ten pages with default numbering
            for (int i = 0; i < totalcount; i++)
            {
                Page pg = new Page();
                doc.Pages.Add(pg);
                PageNumberLabel lbl = new PageNumberLabel();
                pg.Contents.Add(lbl);
            }

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                doc.LayoutComplete += Doc_LayoutCompleted;
                doc.SaveAsPDF(ms);
            }

            for (int i = 0; i < totalcount; i++)
            {
                int           pgNum = i + 1;
                PDFLayoutPage lpg   = layout.AllPages[i];

                PDFPageNumberData data = lpg.GetPageNumber();

                //Check the number
                Assert.AreEqual(pgNum, data.PageNumber);
                Assert.AreEqual(totalcount, data.LastPageNumber);
                Assert.AreEqual(pgNum, data.GroupNumber);
                Assert.AreEqual(totalcount, data.GroupLastNumber);
                Assert.AreEqual(pgNum.ToString(), data.ToString());
            }
        }
        public void DefaultWithSection_Numbered_Test()
        {
            Document doc        = new Document();
            int      totalcount = 10;

            //Add ten pages with default numbering
            for (int i = 0; i < totalcount; i++)
            {
                if (i == 5)
                {
                    Section section = new Section();
                    section.PageNumberStyle = PageNumberStyle.UppercaseLetters;

                    doc.Pages.Add(section);

                    for (int j = 0; j < 4; j++) //4 page breaks = 5 pages
                    {
                        PageBreak br = new PageBreak();
                        section.Contents.Add(br);
                    }
                }
                else
                {
                    Page pg = new Page();
                    doc.Pages.Add(pg);
                    PageNumberLabel lbl = new PageNumberLabel();
                    pg.Contents.Add(lbl);
                }
            }


            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                doc.LayoutComplete += Doc_LayoutCompleted;
                doc.SaveAsPDF(ms);
            }
            string[] allpages = new string[] { "1", "2", "3", "4", "5", "A", "B", "C", "D", "E", "6", "7", "8", "9" };
            string[] grptotal = new string[] { "5", "5", "5", "5", "5", "E", "E", "E", "E", "E", "9", "9", "9", "9" };

            for (int i = 0; i < allpages.Length; i++)
            {
                string expected = string.Format("Page {0} of {1} ({2} of {3})", allpages[i], grptotal[i], i + 1, allpages.Length);

                PDFLayoutPage     lpg  = layout.AllPages[i];
                PDFPageNumberData data = lpg.GetPageNumber();

                string actual = data.ToString("Page {0} of {1} ({2} of {3})");
                Assert.AreEqual(expected, actual);
                TestContext.WriteLine("Expected '{0}', Actual '{1}'", expected, actual);
            }
        }
        public void DocumentPrefixUpperAlpha_Numbered_Test()
        {
            Document doc = new Document();

            //Add a catch all number style definition for upper letter with Prefix
            StyleDefn pgNumStyle = new StyleDefn();

            pgNumStyle.AppliedType = typeof(Document);

            pgNumStyle.PageStyle.NumberStyle = PageNumberStyle.UppercaseLetters;
            doc.Styles.Add(pgNumStyle);


            int totalcount = 10;

            //Add ten pages with default numbering
            for (int i = 0; i < totalcount; i++)
            {
                Page pg = new Page();
                doc.Pages.Add(pg);
                PageNumberLabel lbl = new PageNumberLabel();
                pg.Contents.Add(lbl);
            }


            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                doc.LayoutComplete += Doc_LayoutCompleted;
                doc.SaveAsPDF(ms);
            }

            //Check the numbers
            for (int i = 0; i < totalcount; i++)
            {
                int           pgNum = i + 1;
                PDFLayoutPage lpg   = layout.AllPages[i];

                PDFPageNumberData data = lpg.GetPageNumber();

                //Check the number
                Assert.AreEqual(pgNum, data.PageNumber, "Page Number failed");
                Assert.AreEqual(totalcount, data.LastPageNumber, "Last Page number failed");
                Assert.AreEqual(pgNum, data.GroupNumber, "Group number failed");
                Assert.AreEqual(totalcount, data.GroupLastNumber, "Last Group number failed");

                //Should be upper letter with hash prefix
                string output = ((char)((int)'A' + i)).ToString();
                Assert.AreEqual(output, data.ToString(), "String result failed");
            }
        }
        public void DocumentStyle_WithTitle_PageGroup_AndSection_Test()
        {
            // Blank title page, followed by 2 pages with lower roman, 3 pages in the page group,
            // then inner section of lower alpha and back to a page group single page.

            string[] pgNums = new string[] { "", "i", "ii", "1", "2", "3", "e", "f", "g", "4" };

            //set up the styles

            Document doc = new Document();

            //catch all style will be applied to the document
            StyleDefn catchall = new StyleDefn();

            catchall.PageStyle.NumberStyle = PageNumberStyle.LowercaseRoman;
            catchall.AppliedType           = typeof(Document);
            doc.Styles.Add(catchall);

            //style for the page group
            StyleDefn pgGrpStyle = new StyleDefn();

            pgGrpStyle.AppliedType           = typeof(PageGroup);
            pgGrpStyle.PageStyle.NumberStyle = PageNumberStyle.Decimals;
            doc.Styles.Add(pgGrpStyle);

            //style for the section
            StyleDefn sectStyle = new StyleDefn();

            sectStyle.AppliedType                = typeof(Section);
            sectStyle.PageStyle.NumberStyle      = PageNumberStyle.LowercaseLetters;
            sectStyle.PageStyle.NumberStartIndex = 5;
            doc.Styles.Add(sectStyle);

            //build the document pages to match

            //empty title page

            Page title = new Page();

            title.Style.PageStyle.NumberStyle = PageNumberStyle.None;
            doc.Pages.Add(title);

            // 2 lower roman from the document style

            Page pi = new Page();

            doc.Pages.Add(pi);

            Page pii = new Page();

            doc.Pages.Add(pii);

            //page group with 3 pages of decimals

            PageGroup grp = new PageGroup();

            doc.Pages.Add(grp);

            Page pg1 = new Page();

            grp.Pages.Add(pg1);

            Page pg2 = new Page();

            grp.Pages.Add(pg2);

            Page pg3 = new Page();

            grp.Pages.Add(pg3);

            // section of lower alpha with 3 pages of content

            Section sect = new Section();

            grp.Pages.Add(sect);
            sect.Contents.Add(new PageBreak());
            sect.Contents.Add(new PageBreak());

            // final page in the group
            Page pg4 = new Page();

            grp.Pages.Add(pg4);



            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                doc.LayoutComplete += Doc_LayoutCompleted;
                doc.SaveAsPDF(ms);
            }

            Assert.AreEqual(layout.AllPages.Count, pgNums.Length);

            for (int i = 0; i < pgNums.Length; i++)
            {
                PDFLayoutPage lpg = layout.AllPages[i];

                string expected = pgNums[i];
                string actual   = lpg.GetPageNumber().ToString();

                Assert.AreEqual(expected, actual);
                TestContext.WriteLine("Expected '{0}', Actual '{1}'", expected, actual);
            }
        }