public IActionResult CreatePDF()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.Letter,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "My PDF Report",
                Out           = @"C:\Moje\Visual Studio Projects\PDFGenerator\Report.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHtmlString(_dbRepository),
                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, Right = "[page]", Center = "Report Footer", HtmUrl = Path.Combine(Directory.GetCurrentDirectory(), "assets", "footer.html") }
            };

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

            _converter.Convert(pdf);

            return(Ok("Successfully created PDF document."));
        }
示例#2
0
        public async Task <ActionResult <Models.Enclosure> > GenerateRazorPage()
        {
            var enclosures = _enclosure.GetAll();

            return(new ContentResult {
                ContentType = "text/html",
                StatusCode = (int)HttpStatusCode.OK,
                Content = await _template.GetHtmlString(enclosures),
            });
        }
示例#3
0
        public async Task <FileStreamResult> CreatePdfSync(string guid)
        {
            _logger.LogInformation("Begin create pdf");

            var currentInscription = (await _uow.GetRepository <Inscriptions>().GetAsync(i => i.Guid == guid)).FirstOrDefault();

            if (currentInscription == null)
            {
                throw new ArgumentException("Aucune inscription trouvée");
            }

            string bodyHtml = TemplateGenerator.GetHtmlString(currentInscription.Participant, _urlBaseUpdateSubscription, false);

            _logger.LogError("Content of pdf saved into MemoryCache.");

            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    = bodyHtml, // Convert HTML string to PDF
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "css", "stylePdf.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 }
            };

            //Saving the PDF to the MemoryStream
            var stream = new MemoryStream(_converter.Convert(pdf));

            _logger.LogInformation("End create pdf");

            //Download the PDF document in the browser
            return(await Task.FromResult <FileStreamResult>(new FileStreamResult(stream, "application/pdf")
            {
                FileDownloadName = $"inscriptions-{currentInscription.Participant.Prenom}-{currentInscription.Participant.Nom}.pdf"
            }));
        }
示例#4
0
        public IActionResult Pdf()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "Pdf Export",
                // Out = @"C:\LogFolder\Report.pdf" burası calıstıgı zaman dosyanın indirileceği yeri belirtiyoruz
            };
            var objectSettings = new ObjectSettings
            {
                PagesCount  = true,
                HtmlContent = TemplateGenerator.GetHtmlString(),
                WebSettings =
                {
                    DefaultEncoding = "utf-8",
                    UserStyleSheet  = Path.Combine(Directory.GetCurrentDirectory(), "assets", "style.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);

            return(File(file, "application/pdf", "Info.pdf")); // pdf indirilir
            // return File(file, "application/pdf"); pdf indirilmesin sadece tarayıcı icerisinde göreyim dersen burası
            //return Ok("successfully created pdf, exported LogFolder"); Out özelliğini set edersek burasını acalım
        }
示例#5
0
        public async Task <IActionResult> CreatePdf(int ticketId)
        {
            var ticket = _ticket.GetTicketById(ticketId);

            var globalSettings = new GlobalSettings()
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10, Bottom = 10, Left = 10, Right = 10
                },
                DocumentTitle = "Ticket",
            };

            var objectSetting = new ObjectSettings()
            {
                PagesCount  = true,
                HtmlContent = await _template.GetHtmlString(ticket),
                WebSettings =
                {
                    DefaultEncoding = "utf-8",
                    UserStyleSheet  = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Css/Style.css"),
                    LoadImages      = true
                },
                HeaderSettings = { FontName = "Arial", FontSize = 7, Right = "[page]/[toPage]", Line = true },
            };

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

            var file = _converter.Convert(pdf);

            return(File(file, "applicaation/pdf"));
        }
示例#6
0
        public async Task <IActionResult> CreatePdf()
        {
            var enclosures     = _enclosure.GetAll();
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
                // Out = @"Enclosure.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount  = true,
                HtmlContent = await _template.GetHtmlString(enclosures),
                WebSettings =
                {
                    DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "Style.css")
                },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
            };

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

            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf"));
        }
示例#7
0
        public async Task <FileStreamResult> CreateOnePdfSync(string guid)
        {
            _logger.LogInformation("Begin create pdf-one");

            // Look for cache key.
            if (_memoryCache.TryGetValue($"pdf-html-{guid}", out string bodyHtml))
            {
                _logger.LogError("Content of pdf loaded from MemoryCache.");
            }
            else
            {
                var currentInscription = (await _uow.GetRepository <Inscriptions>().GetAsync(i => i.Guid == guid)).FirstOrDefault();
                if (currentInscription == null)
                {
                    throw new ArgumentException("Aucune inscription trouvée");
                }

                bodyHtml = TemplateGenerator.GetHtmlString(currentInscription.Participant, _urlBaseUpdateSubscription, false, guid);

                // Save data in cache.
                _memoryCache.Set(
                    $"pdf-html-{guid}",
                    bodyHtml,
                    new MemoryCacheEntryOptions
                {
                    AbsoluteExpiration = DateTime.Now.AddMinutes(30),
                    Priority           = CacheItemPriority.Normal
                }
                    );

                _logger.LogError("Content of pdf saved into MemoryCache.");
            }

            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    = bodyHtml, // Convert HTML string to PDF
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "css", "stylePdf.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Right = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }
            };

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

            //Saving the PDF to the MemoryStream
            var stream = new MemoryStream(_converter.Convert(pdf));

            _logger.LogInformation("End create pdf");

            //Download the PDF document in the browser
            return(await Task.FromResult <FileStreamResult>(new FileStreamResult(stream, "application/pdf")
            {
                FileDownloadName = $"inscription-{guid}.pdf"
            }));
        }
示例#8
0
        public async Task <ActionResult <InscriptionBulkModel> > Post(InscriptionBulkModel model)
        {
            try
            {
                if (!model.Colloques.Any() || string.IsNullOrEmpty(model.Participant.Nom) || string.IsNullOrEmpty(model.Participant.Prenom))
                {
                    return(BadRequest("Le nom et le prénom du participant sont obligatoires, et il faut au moins une inscription."));
                }

                var participant = _mapper.Map <Participants>(model.Participant);
                var colloques   = _mapper.Map <List <Colloques> >(model.Colloques);

                _uow.GetRepository <Participants>().Add(participant);

                colloques.ForEach(colloque =>
                {
                    _uow.GetRepository <Inscriptions>().Add(
                        new Inscriptions()
                    {
                        Participant  = participant,
                        ColloqueId   = colloque.Id,
                        DateCreation = DateTime.Now,
                        Guid         = Guid.NewGuid().ToString()
                    });
                });

                if (await _uow.CommitAsync() > 0)
                {
                    if (!string.IsNullOrEmpty(participant.Courriel))
                    {
                        foreach (var inscription in participant.Inscriptions)
                        {
                            inscription.Colloque = colloques.FirstOrDefault(c => c.Id == inscription.ColloqueId);
                        }

                        // Send email confirmation
                        await _emailSender.SendEmail(
                            participant.Courriel,
                            $"{participant.Prenom} {participant.Nom}",
                            TemplateGenerator.GetHtmlString(
                                participant,
                                this.UrlBaseUpdateSubscription,
                                true)
                            );
                    }

                    return(StatusCode(StatusCodes.Status201Created, _mapper.Map <List <InscriptionModel> >(participant.Inscriptions)));
                }
                else
                {
                    _logger.LogWarning($"Erreur lors de l'ajout des inscriptions");

                    return(BadRequest("Erreur lors de l'ajout des inscriptions."));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"inscription-post-bulk : {ex.Message}");

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }