Пример #1
0
        public Task <byte[]> GenerateTransactionHistory(TransactionHistoryPdf transactionHistoryPdf)
        {
            var output    = new MemoryStream();
            var iccStream = new FileStream(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _imageColorMatchingFilename), FileMode.Open, FileAccess.Read);
            var pdfFont   = PdfFontFactory.CreateFont(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _trueTypeFontFilename), PdfEncodings.IDENTITY_H, true);

            try
            {
                var      intent   = new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", iccStream);
                var      pdf      = new PdfADocument(new PdfWriter(output), PdfAConformanceLevel.PDF_A_2B, intent);
                Document document = new Document(pdf);

                if (transactionHistoryPdf.Columns.Any())
                {
                    var table = new Table(6, false);
                    table.AddCell(CreateRootCell(transactionHistoryPdf.Rows.Pid).SetFont(pdfFont));
                    table.AddCell(CreateRootCell(transactionHistoryPdf.Rows.TypeOfObject).SetFont(pdfFont));
                    table.AddCell(CreateRootCell(transactionHistoryPdf.Rows.TypeOfChanges).SetFont(pdfFont));
                    table.AddCell(CreateRootCell(transactionHistoryPdf.Rows.Descriptions).SetFont(pdfFont));
                    table.AddCell(CreateRootCell(transactionHistoryPdf.Rows.Author).SetFont(pdfFont));
                    table.AddCell(CreateRootCell(transactionHistoryPdf.Rows.Date).SetFont(pdfFont));

                    foreach (var column in transactionHistoryPdf.Columns)
                    {
                        table.AddCell(CreateCell(column.Pid).SetFont(pdfFont));
                        table.AddCell(CreateCell(column.TypeOfObject).SetFont(pdfFont));
                        table.AddCell(CreateCell(column.TypeOfChanges).SetFont(pdfFont));
                        table.AddCell(CreateCell(column.Descriptions, TextAlignment.LEFT).SetFont(pdfFont));
                        table.AddCell(CreateCell(column.Author, TextAlignment.LEFT).SetFont(pdfFont));
                        table.AddCell(CreateCell(column.Date, TextAlignment.LEFT).SetFont(pdfFont));
                    }

                    document.Add(table);
                    document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE));
                }

                document.Add(CreateNewLine().SetFont(pdfFont));
                document.Add(CreateLineSeparator().SetFont(pdfFont));
                document.Add(CreateTextAlignment(transactionHistoryPdf.Name).SetFont(pdfFont));
                document.Add(CreateTextAlignment(transactionHistoryPdf.Originator).SetFont(pdfFont));
                document.Add(CreateTextAlignment(transactionHistoryPdf.Address).SetFont(pdfFont));
                document.Add(CreateTextAlignment(transactionHistoryPdf.SerialNumber).SetFont(pdfFont));
                document.Add(CreateTextAlignment($"{transactionHistoryPdf.NumberOfPages}{pdf.GetNumberOfPages()}").SetFont(pdfFont));

                var numberOfPages = pdf.GetNumberOfPages();

                pdf.MovePage(numberOfPages, 1);

                for (int pageNum = 1; pageNum <= numberOfPages; pageNum++)
                {
                    Rectangle pageSize = pdf.GetPage(pageNum).GetPageSize();

                    if (pageNum != 1)
                    {
                        document.ShowTextAligned(CreateTextAlignment(transactionHistoryPdf.Header, 7).SetFont(pdfFont), pageSize.GetLeft() + 35, pageSize.GetTop() - 13, pageNum, TextAlignment.LEFT, VerticalAlignment.TOP, 0);
                    }

                    document.ShowTextAligned(CreateText(pageNum + " / " + numberOfPages, 7).SetFont(pdfFont), pageSize.GetWidth() / 2, pageSize.GetBottom() + 15, pageNum, TextAlignment.CENTER, VerticalAlignment.BOTTOM, 0);
                }

                document.Close();

                return(Task.FromResult(output.ToArray()));
            }
            finally
            {
                iccStream.Dispose();
                output.Dispose();
            }
        }
Пример #2
0
        public async Task <TransactionHistoryPdf> ToPdfModel(DateTime currentDate)
        {
            var mainGroup = await _alfrescoHttpClient.GetGroupMembers(JobsNames.MainGroup,
                                                                      ImmutableList <Parameter> .Empty.Add(new Parameter(AlfrescoNames.Headers.Where, AlfrescoNames.MemberType.Group, ParameterType.QueryString)));

            var pdfCount = await _alfrescoHttpClient.GetNodeChildren(AlfrescoNames.Aliases.Root, ImmutableList <Parameter> .Empty
                                                                     .Add(new Parameter(AlfrescoNames.Headers.MaxItems, 1, ParameterType.QueryString))
                                                                     .Add(new Parameter(AlfrescoNames.Headers.RelativePath, JobsNames.DailyFingerPrintPath, ParameterType.QueryString))
                                                                     .Add(new Parameter(AlfrescoNames.Headers.Where, $"(nodeType='{AlfrescoNames.ContentModel.Content}')", ParameterType.QueryString)));

            var transactionHistory = await _transactionHistoryRepository.GetTransactionHistoryByDate(currentDate.Date, currentDate.Date);

            var pdfCounter = pdfCount?.List?.Pagination?.TotalItems.HasValue == true ? pdfCount.List.Pagination.TotalItems.Value : 1;

            TransactionHistoryPdf transactionHistoryObj = new TransactionHistoryPdf
            {
                Header        = string.Format(PdfTranslations.PageHeader, _transactionHistoryConfiguration?.Originator, currentDate.ToString("dd.MM.yyyy")),
                Name          = string.Format(PdfTranslations.FirstPage.Name, currentDate.ToString("dd.MM.yyyy")),
                Originator    = string.Format(PdfTranslations.FirstPage.Originator, _transactionHistoryConfiguration?.Originator),
                Address       = string.Format(PdfTranslations.FirstPage.Address, _transactionHistoryConfiguration?.Address),
                SerialNumber  = string.Format(PdfTranslations.FirstPage.SerialNumber, ++pdfCounter),
                NumberOfPages = PdfTranslations.FirstPage.NumberOfPages,
                Rows          = new TableRows
                {
                    Pid           = PdfTranslations.Cells.Pid,
                    TypeOfObject  = PdfTranslations.Cells.TypeOfObject,
                    TypeOfChanges = PdfTranslations.Cells.TypeOfChanges,
                    Descriptions  = PdfTranslations.Cells.Descriptions,
                    Author        = PdfTranslations.Cells.Author,
                    Date          = PdfTranslations.Cells.Date
                },
                Columns = new List <TableColumns>()
            };

            foreach (var item in transactionHistory)
            {
                TransactionHistoryParameters eventParams = null;

                if (item.EventParameters != null)
                {
                    eventParams = JsonConvert.DeserializeObject <TransactionHistoryParameters>(item.EventParameters);
                }

                string requestGroup = mainGroup?.List?.Entries?.FirstOrDefault(u => u.Entry.Id == item.UserGroupId)?.Entry?.DisplayName ?? item.UserGroupId;

                if (eventParams != null)
                {
                    transactionHistoryObj.Columns.Add(new TableColumns
                    {
                        Pid           = item.Pid,
                        TypeOfObject  = item.FkNodeTypeCodeNavigation.Code,
                        TypeOfChanges = item.FkEventTypeCodeNavigation.Code,
                        Descriptions  = eventParams.Message,
                        Author        = string.Join("; ", item.UserId, requestGroup),
                        Date          = item.OccuredAt.ToString("dd.MM.yyyy hh:mm:ss")
                    });
                }
                else
                {
                    transactionHistoryObj.Columns.Add(new TableColumns
                    {
                        Pid           = item.Pid,
                        TypeOfObject  = item.FkNodeTypeCodeNavigation.Code,
                        TypeOfChanges = "",
                        Descriptions  = item.FkEventTypeCodeNavigation.Code,
                        Author        = string.Join(";", item.UserId, requestGroup),
                        Date          = item.OccuredAt.ToString("dd.MM.yyyy hh:mm:ss")
                    });
                }
            }

            return(transactionHistoryObj);
        }