예제 #1
0
        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());
                }
            }
        }
        void Draw()
        {
            _interpolatedFieldsList = _krigingSelectionControl.GetSelectedMaps();
            setMapsCount();

            updateProgressbar(0);

            if (_interpolatedFieldsList.Count > 0)
            {
                int columnsCount = 1;
                int width = 90;

                if (_mapsCount == 2)
                {
                    columnsCount = 1;
                    width = 45;
                }
                else if (_mapsCount == 4)
                {
                    columnsCount = 2;
                    width = 90;
                }

                _tblKrigingMapImage = new PdfPTable(columnsCount);

                _tblKrigingMapImage.DefaultCell.Padding = 0;
                _tblKrigingMapImage.DefaultCell.Border = 0;
                _tblKrigingMapImage.TotalWidth = _document.PageSize.Width;
                _tblKrigingMapImage.WidthPercentage = width;

                double pages = Math.Ceiling((double)_interpolatedFieldsList.Count / _mapsCount);

                int addedItems = 0;

                for (int p = 0; p < pages; p++)
                {
                    _document.NewPage();

                    addedItems = 0;

                    foreach (var item in _interpolatedFieldsList.Skip(_mapsCount * p).Take(_mapsCount))
                    {
                        clearPanelControl();

                        if (!string.IsNullOrEmpty(item.Image) && !string.IsNullOrEmpty(item.ColorsCategories))
                        {
                            var colorsList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Repository.Utils.LegendPattern>>(item.ColorsCategories);

                            if (_mapsCount == 1)
                            {
                                var ctrl = new MainApp.Controls.KrigingViewerControl(colorsList, item);
                                addControlViewPanel(ctrl);
                            }
                            else
                            {
                                var ctrl = new MainApp.Controls.KrigingViewerSmallControl(colorsList, item);
                                addControlViewPanel(ctrl);
                                addedItems++;
                            }
                        }
                        else
                        {
                            _backgroundWorker.ReportProgress(_progressBar.Value + 1);
                        }
                    }

                    if (_mapsCount - addedItems > 0)
                    {
                        for (int i = 1; i <= (_mapsCount - addedItems); i++)
                        {
                            _tblKrigingMapImage.AddCell("");
                        }
                    }
                }

            }
            else
            {
                _backgroundWorker.ReportProgress(0);
            }

        }