public void PageRomanLowerCollection() { int repeatcount = 20; //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 string[] expected = { "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv", "xvi", "xvii", "xviii", "xix", "xx" }; PDFPageNumbers col = new PDFPageNumbers(); col.StartNumbering(null); Style full = new Style(); full.PageStyle.NumberStyle = PageNumberStyle.LowercaseRoman; PDFPageNumberOptions opts = full.CreatePageNumberOptions(); col.PushPageNumber(opts); col.Register(0); col.UnRegister(19); col.EndNumbering(); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); Assert.AreEqual(expected[i], actual); } }
public void PageRomanUpperWithStartIndexAndPrefixCollection() { int startindex = 4; int repeatcount = 20; //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 string[] expected = { "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", "XXIII" }; PDFPageNumbers col = new PDFPageNumbers(); Style style = new Style(); style.PageStyle.NumberStyle = PageNumberStyle.UppercaseRoman; style.PageStyle.NumberStartIndex = startindex; col.StartNumbering(style.CreatePageNumberOptions()); col.Register(0); col.UnRegister(19); col.EndNumbering(); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); Assert.AreEqual(expected[i], actual); } }
public void PageEmptyCollection() { int repeatcount = 20; //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 string[] expected = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }; PDFPageNumbers col = new PDFPageNumbers(); col.StartNumbering(null); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); Assert.AreEqual(expected[i], actual); } }
public void PageNoneCollection() { int repeatcount = 20; PDFPageNumbers col = new PDFPageNumbers(); Style style = new Style(); style.PageStyle.NumberStyle = PageNumberStyle.None; col.StartNumbering(style.CreatePageNumberOptions()); col.Register(0); col.UnRegister(19); col.EndNumbering(); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); string expected = string.Empty; Assert.AreEqual(expected, actual); } }
/// <summary> /// Writes the collection of page labels and returns a reference to this collection /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> private PDFObjectRef WritePageLabels(PDFRenderContext context, PDFWriter writer) { PDFPageNumbers nums = this.Numbers; PDFObjectRef labels = writer.BeginObject("PageLabels"); writer.BeginDictionary(); writer.BeginDictionaryEntry("Nums"); writer.BeginArrayS(); //PDFPageNumberRegistration def = this.Numbers.; //this.WriteAPageLabel(context, writer, def); foreach (PDFPageNumberRegistration entry in this.Numbers.Registrations) { WriteAPageLabel(context, writer, entry); } writer.EndArray(); writer.EndDictionaryEntry(); writer.EndDictionary(); writer.EndObject(); return(labels); }
public void PageDecimalsCollection() { int repeatcount = 20; //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 string[] expected = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }; PDFPageNumbers col = new PDFPageNumbers(); PDFPageNumberOptions options = new PDFPageNumberOptions() { NumberStyle = PageNumberStyle.Decimals }; col.StartNumbering(options); col.Register(0); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); Assert.AreEqual(expected[i], actual); } }
public void PageLetterUpperCollection() { int repeatcount = 29; //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 string[] expected = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "AA", "BB", "CC" }; PDFPageNumbers col = new PDFPageNumbers(); Style full = new Style(); full.PageStyle.NumberStyle = PageNumberStyle.UppercaseLetters; col.StartNumbering(full.CreatePageNumberOptions()); col.Register(0); col.UnRegister(28); col.EndNumbering(); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); Assert.AreEqual(expected[i], actual); } }
public void PageLetterLowerCollection() { int repeatcount = 29; //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 string[] expected = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "aa", "bb", "cc" }; PDFPageNumbers col = new PDFPageNumbers(); Style full = new Style(); full.PageStyle.NumberStyle = PageNumberStyle.LowercaseLetters; col.StartNumbering(full.CreatePageNumberOptions()); col.Register(0); col.UnRegister(28); col.EndNumbering(); for (int i = 0; i < repeatcount; i++) { string actual = col.GetPageLabel(i); Assert.AreEqual(expected[i], actual); } }
public void PageCollection_Nested() { // structure | None | Start | Reset Numbers | Back To Start sequence | Back to None // output | 0 1 2 | 3 4 5 6 | 7 8 9 10 11 12 13 14 | 15 16 17 18 | 19 20 21 string[] expectedLabels = { "", "", "", "i", "ii", "iii", "iv", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "v", "vi", "vii", "viii", "", "", "" }; string[] expectedLastLabels = { "", "", "", "iv", "iv", "iv", "iv", "viii", "viii", "viii", "viii", "viii", "viii", "viii", "viii", "viii", "viii", "viii", "viii", "", "", "" }; PDFPageNumbers col = new PDFPageNumbers(); col.StartNumbering(null); Style none = new Style(); none.PageStyle.NumberStyle = PageNumberStyle.None; PDFPageNumberGroup noneGrp = col.PushPageNumber(none.CreatePageNumberOptions()); int noneReg = 0; col.Register(noneReg); //keep none at the top - no unregister Style intro = new Style(); intro.PageStyle.NumberStyle = PageNumberStyle.LowercaseRoman; PDFPageNumberGroup introGrp = col.PushPageNumber(intro.CreatePageNumberOptions()); int introReg = 3; col.Register(introReg); //col.UnRegister(introUnreg); //col.PopNumberStyle(grp); //no style, just start index Style resetStartIndex = new Style(); resetStartIndex.PageStyle.NumberStartIndex = 1; PDFPageNumberGroup resetNumGrp = col.PushPageNumber(resetStartIndex.CreatePageNumberOptions()); int pgReg = 7; int pgUnreg = 14; col.Register(pgReg); col.UnRegister(pgUnreg); col.PopNumberStyle(resetNumGrp); int introUnreg = 18; col.UnRegister(introUnreg); col.PopNumberStyle(introGrp); int noneUnReg = 21; col.UnRegister(noneUnReg); col.PopNumberStyle(noneGrp); col.EndNumbering(); for (int i = 0; i < 21; i++) { PDFPageNumberData number = col.GetPageData(i); Assert.AreEqual(expectedLabels[i], number.Label, "Page labels did not match for index " + i); Assert.AreEqual(expectedLastLabels[i], number.LastLabel, "Page Last labels did not match for index " + i); } }
public void PageCollection_DefaultAndBack() { // page indices 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 , 12, 13, 14, 15, 16, 17, 18, 19 string[] expectedlabels = new string[] { "1", "2", "3", "4", "5", "i", "ii", "iii", "iv", "v", "B", "C", "D", "E", "F", "6", "7", "8", "9", "10" }; PDFPageNumbers col = new PDFPageNumbers(); Style def = new Style(); def.PageStyle.NumberStyle = PageNumberStyle.Decimals; def.PageStyle.NumberStartIndex = 1; col.StartNumbering(def.CreatePageNumberOptions()); Style lowRoman = new Style(); lowRoman.PageStyle.NumberStyle = PageNumberStyle.LowercaseRoman; lowRoman.PageStyle.NumberStartIndex = 1; Style alpha = new Style(); alpha.PageStyle.NumberStyle = PageNumberStyle.UppercaseLetters; alpha.PageStyle.NumberStartIndex = 2; col.Register(0); col.Register(1); col.Register(2); col.Register(3); col.Register(4); PDFPageNumberGroup grp = col.PushPageNumber(lowRoman.CreatePageNumberOptions()); col.Register(5); col.Register(6); col.Register(7); col.Register(8); col.Register(9); col.UnRegister(9); col.PopNumberStyle(grp); grp = col.PushPageNumber(alpha.CreatePageNumberOptions()); col.Register(10); col.Register(11); col.Register(12); col.Register(13); col.Register(14); col.UnRegister(14); col.PopNumberStyle(grp); col.Register(15); col.Register(16); col.Register(17); col.Register(18); col.Register(19); col.UnRegister(19); col.EndNumbering(); for (int i = 0; i < 20; i++) { string lbl = col.GetPageLabel(i); Assert.AreEqual(expectedlabels[i], lbl); } }
public void PageNumbering_MultiSectionDocument() { Document doc = new Document(); // numbering | Default | Lower roman | Upper letter with prefix | Back to default // page indices 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 , 12, 13, 14, 15, 16, 17, 18, 19 string[] expectedlabels = new string[] { "1", "2", "3", "4", "5", "i", "ii", "iii", "iv", "v", "B", "C", "D", "E", "F", "6", "7", "8", "9", "10" }; for (int i = 0; i < 4; i++) { Section group = new Section(); if (i == 1) { group.Style.PageStyle.NumberStyle = PageNumberStyle.LowercaseRoman; group.Style.PageStyle.NumberStartIndex = 1; } else if (i == 2) { group.Style.PageStyle.NumberStyle = PageNumberStyle.UppercaseLetters; group.Style.PageStyle.NumberStartIndex = 2; } doc.Pages.Add(group); for (int j = 0; j < 4; j++) { PageBreak br = new PageBreak(); group.Contents.Add(br); } } doc.ViewPreferences.PageDisplay = PageDisplayMode.Thumbnails; doc.LayoutComplete += Doc_LayoutComplete; using (var ms = DocStreams.GetOutputStream("Numbering_MultiSection.pdf")) doc.SaveAsPDF(ms); var ldoc = this._layout; int index = -1; List <string> actuallabels = new List <string>(); Assert.AreEqual(20, ldoc.AllPages.Count); int last = -1; foreach (Scryber.Layout.PDFLayoutPage pg in ldoc.AllPages) { index = pg.PageIndex; Assert.AreEqual(last + 1, index, "Page numbers are not in synch"); last = index; //Get the page number details for the page PDFPageNumberData num = pg.GetPageNumber(); actuallabels.Add(num.Label); if (index < 5) { Assert.AreEqual(index + 1, num.GroupNumber, "First block page group number was wrong"); Assert.AreEqual(index + 1, num.PageNumber, "First block Global page number was wrong"); Assert.AreEqual(20, num.LastPageNumber, "First block last page number was wrong"); Assert.AreEqual(5, num.GroupLastNumber, "First block last group number was wrong"); Assert.AreEqual(expectedlabels[index], num.Label, "First block page label was wrong"); Assert.AreEqual("5", num.LastLabel, "First block last label was wrong"); } else if (index < 10) { Assert.AreEqual(index + 1, num.PageNumber, "First block page group number was wrong"); Assert.AreEqual(20, num.LastPageNumber, "First block Global page number was wrong"); index -= 5; Assert.AreEqual(index + 1, num.GroupNumber); Assert.AreEqual(5, num.GroupLastNumber); Assert.AreEqual(Scryber.Utilities.NumberHelper.GetRomanLower(index + 1), num.Label); Assert.AreEqual("v", num.LastLabel); } else if (index < 15) { Assert.AreEqual(index + 1, num.PageNumber); Assert.AreEqual(20, num.LastPageNumber); index -= 10; Assert.AreEqual(index + 1, num.GroupNumber); Assert.AreEqual(5, num.GroupLastNumber); Assert.AreEqual(Scryber.Utilities.NumberHelper.GetLetterUpper(index + 2), num.Label); Assert.AreEqual("F", num.LastLabel); } else { Assert.AreEqual(index + 1, num.PageNumber); Assert.AreEqual(20, num.LastPageNumber); //group is one based from the start of that sequence index -= 15; Assert.AreEqual(index + 1, num.GroupNumber); Assert.AreEqual(5, num.GroupLastNumber); //labels are based from the start of that entire sequence index += 5; Assert.AreEqual((index + 1).ToString(), num.Label); Assert.AreEqual("10", num.LastLabel); } } string fullexpected = string.Join(", ", expectedlabels); string fullactual = string.Join(", ", actuallabels); Assert.AreEqual(fullexpected, fullactual); //Check the page registrations // numbering | Default | Lower roman | Upper letter with prefix | Back to default // page indices 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 , 12, 13, 14, 15, 16, 17, 18, 19 PDFPageNumbers nums = ldoc.Numbers; Assert.AreEqual(4, nums.Registrations.Count); //Default 1-4 PDFPageNumberRegistration reg = nums.Registrations[0]; Assert.AreEqual(0, reg.FirstPageIndex); Assert.AreEqual(4, reg.LastPageIndex); Assert.AreEqual(0, reg.PreviousLinkedRegistrationPageCount); Assert.AreEqual(true, reg.IsClosed); //Lower Roman 5-9 reg = nums.Registrations[1]; Assert.AreEqual(5, reg.FirstPageIndex); Assert.AreEqual(9, reg.LastPageIndex); Assert.AreEqual(0, reg.PreviousLinkedRegistrationPageCount); Assert.AreEqual(true, reg.IsClosed); //Lower Upper Letter with prefix 10-14 reg = nums.Registrations[2]; Assert.AreEqual(10, reg.FirstPageIndex); Assert.AreEqual(14, reg.LastPageIndex); Assert.AreEqual(0, reg.PreviousLinkedRegistrationPageCount); Assert.AreEqual(true, reg.IsClosed); //Lower Default 15-19 reg = nums.Registrations[3]; Assert.AreEqual(15, reg.FirstPageIndex); Assert.AreEqual(19, reg.LastPageIndex); Assert.AreEqual(5, reg.PreviousLinkedRegistrationPageCount); //restarting from the last default onto this page Assert.AreEqual(true, reg.IsClosed); }
// // page numbers // #region public void StartPageNumbering(PDFPageNumberOptions opts) /// <summary> /// Called at the start of document layout to initialize the numbering collection /// </summary> /// <param name="style"></param> public void StartPageNumbering(PDFPageNumberOptions opts) { this._numbers = new PDFPageNumbers(); this._numbers.StartNumbering(opts); }