private static Dictionary <string, ISPage> BuildPageMap(string baseRoom, string dirPath) { var pageMap = new Dictionary <string, ISPage>(); ISPageHtmlParser.BuildAllISPages(pageMap, baseRoom, dirPath).Wait(); return(pageMap); }
private void BuildPDF(Dictionary <string, ISPage> pageMap, string baseRoom, Dictionary <string, int> chapterPageMap, bool fakeRun) { if (fakeRun) { ISPageHtmlParser.BuildAllISPages(pageMap, baseRoom, filePath).Wait(); } //now that we have all the pages, we'll have to clean them up and decide on pages Dictionary <string, int> ISPageToPhysicalPageMap = new Dictionary <string, int>(); int currentPage = 1; int currentChapter = 1; Random r = new Random(123456); List <string> pagesLeft = new List <string>(pageMap.Count); foreach (string x in pageMap.Keys) { pagesLeft.Add(x); } using (MemoryStream memStream = new MemoryStream()) { Document pdfDoc = new Document(); iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, memStream); HeaderFooter evnt = new HeaderFooter(); if (fakeRun) { evnt.pageByTitle = chapterPageMap; } else { evnt.pageByTitle = new Dictionary <string, int>(); } if (!fakeRun) { writer.PageEvent = evnt; } pdfDoc.Open(); pdfDoc.AddAuthor("test"); pdfDoc.AddTitle("testTitle"); while (pagesLeft.Any()) { string pageToAdd = pagesLeft.First(); if (currentPage > 1) { pagesLeft.Skip(r.Next(pagesLeft.Count)).First(); } pagesLeft.Remove(pageToAdd); if (fakeRun) { chapterPageMap.Add(pageToAdd, writer.PageNumber + 1); } ISPageToPhysicalPageMap.Add(pageToAdd, currentPage); var chapter = GetPDFPage(pageMap[pageToAdd], int.Parse(pageToAdd), chapterPageMap); pdfDoc.Add(chapter); int actualPageLength = fakeRun ? 1 : chapterPageMap[pageToAdd]; currentPage += actualPageLength; currentChapter++; } pdfDoc.Close(); writer.Close(); if (!fakeRun) { File.WriteAllBytes(Path.Combine(filePath, fileName), memStream.GetBuffer()); } } }