Esempio n. 1
0
        public IActionResult CreatePdfFacture(Facture PdfFacture)
        {
            var webRoothPath   = _hostingEnvironment.WebRootPath;
            var IdUser         = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
                //Out = @"C:\PDFCreator\Employee_Report.pdf"
                Out = webRoothPath + "/pdfFactures/" + PdfFacture.IdFacture + ".pdf"
            };
            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLFactureString(PdfFacture),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "PdfStyles.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);

            //var uploads = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
            //using (var fileStream = new FileStream(Path.Combine(uploads, "test"), FileMode.Create))
            //{
            //    await pdf.CopyToAsync(fileStream);
            //}

            //return File(file, "application/pdf", PdfFacture.IdFacture + ".pdf");
            //return File(file, "application/pdf");
            return(Ok("Successfully created PDF document."));
        }