Пример #1
0
        public StockCollection Get(int countPerPage, int page)
        {
            _stockCollection            = _xmlToCollection.Execute();
            _stockCollection.StockCount = _stockCollection.Stocks.Count;

            var tempResult = new StockCollection()
            {
                Stocks     = _stockCollection.Stocks.Skip(countPerPage * (page - 1)).Take(countPerPage).ToList(),
                StockCount = _stockCollection.StockCount
            };

            return(tempResult);
        }
        public IActionResult CreatePDF(int countPerPage = 10, int page = 1)
        {
            _stockCollection = _xmlToCollection.Execute();

            List <Stock> list = _stockCollection.Stocks.Skip(countPerPage * (page - 1)).Take(countPerPage).ToList();

            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Reports",
            };

            var objectSetting = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(list),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "style.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 12, Right = "Page [Page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 12, Center = "Report Footer", Line = true }
            };

            var pdf = new HtmlToPdfDocument
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSetting }
            };

            var file = _converter.Convert(pdf);


            return(File(file, "application/pdf"));
        }