Пример #1
0
            public async Task <string> Handle(SettlementMatterGeneratePDFQuery message, CancellationToken token)
            {
                ValidationResult result = _validator.Validate(message);

                if (!result.IsValid)
                {
                    throw new ValidationException("Invalid input.", result.Errors);
                }

                SettlementInfo settlementInfo = message.Matter.SettlementData;

                var matterInfo = await _mediator.Send(new ActionstepMatterInfoQuery(message.Matter.ActionstepOrgKey, message.Matter.ActionstepMatterId, message.AuthenticatedUser));

                var pdfContent = settlementInfo.GeneratePDFContent(matterInfo.OrgName);

                var tempPdfPath = Path.GetTempFileName();

                var doc = new HtmlToPdfDocument()
                {
                    GlobalSettings =
                    {
                        ColorMode   = ColorMode.Color,
                        Orientation = Orientation.Portrait,
                        PaperSize   = PaperKind.A4,
                        Out         = tempPdfPath
                    },
                    Objects =
                    {
                        new ObjectSettings()
                        {
                            PagesCount     = true,
                            HtmlContent    = pdfContent,
                            WebSettings    = { DefaultEncoding = "utf-8" },
                            HeaderSettings ={ Line                                 = false, Spacing = 3}
                        }
                    }
                };

                _converter.Convert(doc);

                return(tempPdfPath);
            }