Beispiel #1
0
        public async Task <IActionResult> GetById([FromRoute] Guid ticketId)
        {
            GetTicketRequest ticket;

            try
            {
                ticket = await _ticketService.GetTicketById(ticketId);
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }

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

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = PdfGenerator.GetHTMLString(ticket),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            Convert.ToBase64String(file);

            return(Ok(file));
        }