Exemplo n.º 1
0
        private static void CreateTemplate(SkuPdfModel model)
        {
            var pdfDocument = new Document();

            using var imageStore = new ImageStore();
            var page = pdfDocument.Pages.Add();

            // Header Table
            var headerTable = CreateHeaderTable(model, imageStore);

            page.Paragraphs.Add(headerTable);

            // Characteristic Table
            var characteristicTable = CreateCharacteristicTable(model);

            page.Paragraphs.Add(characteristicTable);

            // Classification Table
            var classificationTable = CreateClassificationTable(model);

            page.Paragraphs.Add(classificationTable);

            // Classification Table
            var supplierOffersTable = CreateSupplierOffersTable(model);

            page.Paragraphs.Add(supplierOffersTable);


            using var resultStream = File.Open("D:\\WorkAsposeFiles\\template.pdf", FileMode.Create);
            pdfDocument.Save(resultStream, SaveFormat.Pdf);
        }
Exemplo n.º 2
0
        private static Table CreateClassificationTable(SkuPdfModel model)
        {
            return(TableBuilder.Create(builder =>
            {
                builder.SetCellPaddings(5f);
                builder.SetColumnWidths(2, "200 300");
                builder.SetDefaultTextStyle();
                //builder.AddBorders();

                builder.AddSingleCellRow(cellBuilder =>
                {
                    cellBuilder.Cell.Margin = new MarginInfo(0, 12, 0, 15);
                    cellBuilder.AddHtml(fragmentBuilder => fragmentBuilder.AppendHeader("Классификация"));
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.Row.BackgroundColor = Color.FromRgb(231 / 255f, 239 / 255f, 247 / 255f);

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Справочник");
                    }));

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Код");
                    }));
                });

                foreach (var classification in model.Classifications)
                {
                    builder.AddRow(rowBuilder =>
                    {
                        rowBuilder.Row.Border = new BorderInfo(BorderSide.Top,
                                                               new GraphInfo {
                            Color = Color.Gray, LineWidth = 0.5f
                        });

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder.AppendText(classification.Dictionary);
                        }));

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder.AppendText(classification.Code);
                        }));
                    });
                }
            }));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            foreach (var process in Process.GetProcessesByName("AcroRd32"))
            {
                process.Kill();
            }

            using var fileStream = File.Open("D:\\WorkAsposeFiles\\License.txt", FileMode.Open);

            var pdf = new Aspose.Pdf.License();

            pdf.SetLicense(fileStream);
            fileStream.Seek(0, SeekOrigin.Begin);

            var word = new Aspose.Words.License();

            word.SetLicense(fileStream);
            fileStream.Seek(0, SeekOrigin.Begin);

            var cells = new Aspose.Cells.License();

            cells.SetLicense(fileStream);

            var model = new SkuPdfModel()
            {
                Characteristics = new List <Characteristic>
                {
                    new Characteristic("Количество листов в пачке", "45 шт"),
                    new Characteristic("Класс бумаги", "C"),
                    new Characteristic("Плотность бумаги", "80 гр/м2"),
                    new Characteristic("Страна происхождения", "Россия")
                },
                Classifications = new List <Classification>
                {
                    new Classification("ОКПД2", "32.99.12.120 Ручки и маркеры с наконечником из фетра и прочих пористых материалов"),
                    new Classification("КПГЗ", "01.15.05.03.04 Принадлежности для досок и флипчартов"),
                    new Classification("КТРУ", "32.99.12.120-00000001 Маркер")
                },
                SupplierOffers = new List <SupplierOffer>
                {
                    new SupplierOffer("ООО \"ЯСТРЕБ\"", "5427713792", "1219511-21", "5-10 дней", "г Москва, обл Московская", 47, 20),
                    new SupplierOffer("ИП ВЛАДИМИР", "4767898456", "4578548-45", "2-3 часа", "г Казань, Татарстан", 30, 20),
                    new SupplierOffer("ООО \"ЖЕНЕРИК\"", "7894598723", "6578459-12", "1-2 недели", "г Москва, обл Московская", 50, 20)
                }
            };

            CreateTemplate(model);

            Process.Start("D:\\WorkAsposeFiles\\template.pdf");
        }
Exemplo n.º 4
0
        private static Table CreateHeaderTable(SkuPdfModel model, ImageStore imageStore)
        {
            var table = TableBuilder.Create(builder =>
            {
                builder.SetCellPaddings(5f);
                builder.SetColumnWidths(3, "150 150 150");
                builder.SetDefaultTextStyle();
                //builder.AddBorders();

                builder.AddRow(rowBuilder =>
                {
                    var image = imageStore.GetImage("D:\\WorkAsposeFiles\\2.png", image => image.ImageScale = 0.6);

                    rowBuilder.AddCell(3, cellBuilder =>
                    {
                        cellBuilder.AddImage(image);
                    });
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.AddCell(2, cellBuilder =>
                    {
                        cellBuilder.Cell.VerticalAlignment = VerticalAlignment.Center;
                        cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder.AppendHighlighted(model.Name).Build();
                        });
                    });

                    rowBuilder.AddCell(cellBuilder =>
                    {
                        var qr = imageStore.GetImage(
                            "D:\\WorkAsposeFiles\\3.gif",
                            image =>
                        {
                            image.FixHeight           = 80;
                            image.FixWidth            = 80;
                            image.VerticalAlignment   = VerticalAlignment.Top;
                            image.HorizontalAlignment = HorizontalAlignment.Right;
                        });

                        cellBuilder.AddImage(qr);
                    });
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.AddCell(cellBuilder =>
                    {
                        var sku = imageStore.GetImage("D:\\WorkAsposeFiles\\1.jpg", image =>
                        {
                            image.FixHeight = 150;
                            image.FixWidth  = 150;
                        });

                        cellBuilder.Cell.RowSpan = 3;
                        cellBuilder.AddImage(sku);
                    });

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder
                        .AppendText("Референтная цена")
                        .AppendHighlighted(model.ReferencePrice)
                        .AppendText("штука");
                    }));

                    rowBuilder.AddCell(cellBuilder =>
                    {
                        cellBuilder.Cell.Alignment         = HorizontalAlignment.Right;
                        cellBuilder.Cell.VerticalAlignment = VerticalAlignment.Top;

                        cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder
                            .AppendText("Контрактов")
                            .AppendHighlighted(model.ContractsCount);
                        });
                    });
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.AddCell(2, cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder
                        .AppendHighlighted($"от {model.MinPrice} до {model.MaxPrice}")
                        .AppendText("на основе 24 предложений поставщиков");
                    }));
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.AddCell(2, cellBuilder =>
                    {
                        cellBuilder.Cell.VerticalAlignment = VerticalAlignment.Top;

                        cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder
                            .AppendText("Востребованная продукция");
                        });
                    });
                });
            });

            return(table);
        }
Exemplo n.º 5
0
        private static Table CreateCharacteristicTable(SkuPdfModel model)
        {
            return(TableBuilder.Create(builder =>
            {
                builder.SetCellPaddings(5f);
                builder.SetColumnWidths(2, "200 300");
                builder.SetDefaultTextStyle();
                //builder.AddBorders();

                builder.AddSingleCellRow(cellBuilder =>
                {
                    cellBuilder.Cell.Margin = new MarginInfo(0, 0, 0, 10);
                    cellBuilder.AddHtml(fragmentBuilder => fragmentBuilder.AppendHeader("Характеристики"));
                });

                builder.AddSingleCellRow(cellBuilder =>
                {
                    cellBuilder.AddHtml(fragmentBuilder =>
                    {
                        fragmentBuilder
                        .AppendText("Модель: " + model.SkuModel)
                        .AppendText("Производитель: " + model.Producer);
                    });
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.Row.BackgroundColor = Color.FromRgb(231 / 255f, 239 / 255f, 247 / 255f);

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Наименование характеристики");
                    }));

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Значение");
                    }));
                });

                foreach (var characteristic in model.Characteristics)
                {
                    builder.AddRow(rowBuilder =>
                    {
                        rowBuilder.Row.Border = new BorderInfo(BorderSide.Top,
                                                               new GraphInfo {
                            Color = Color.Gray, LineWidth = 0.5f
                        });

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder.AppendText(characteristic.Name);
                        }));

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder.AppendText(characteristic.Value);
                        }));
                    });
                }
            }));
        }
Exemplo n.º 6
0
        private static Table CreateSupplierOffersTable(SkuPdfModel model)
        {
            return(TableBuilder.Create(builder =>
            {
                builder.SetCellPaddings(5f);
                builder.SetColumnWidths(3, "150 200 100");
                builder.SetDefaultTextStyle();

                builder.AddSingleCellRow(cellBuilder =>
                {
                    cellBuilder.Cell.Margin = new MarginInfo(0, 12, 0, 15);
                    cellBuilder.AddHtml(fragmentBuilder => fragmentBuilder.AppendHeader("Предложения поставщиков"));
                });

                builder.AddRow(rowBuilder =>
                {
                    rowBuilder.Row.BackgroundColor = Color.FromRgb(231 / 255f, 239 / 255f, 247 / 255f);

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Поставщик");
                    }));

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Условия поставки");
                    }));

                    rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                    {
                        htmlBuilder.AppendText("Стоимость с НДС");
                    }));
                });

                foreach (var supplierOffer in model.SupplierOffers)
                {
                    builder.AddRow(rowBuilder =>
                    {
                        rowBuilder.Row.Border = new BorderInfo(BorderSide.Top,
                                                               new GraphInfo {
                            Color = Color.Gray, LineWidth = 0.5f
                        });

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder
                            .AppendBoldText(supplierOffer.Name)
                            .AppendText($"ИНН: {supplierOffer.Inn}")
                            .AppendText($"Оферта: №: {supplierOffer.Offer}");
                        }));

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder
                            .AppendText($"Срок поставки: {supplierOffer.DeliveryTime}")
                            .AppendText($"Регион поставки: {supplierOffer.DeliveryRegion}");
                        }));

                        rowBuilder.AddCell(cellBuilder => cellBuilder.AddHtml(htmlBuilder =>
                        {
                            htmlBuilder
                            .AppendHighlighted($"{supplierOffer.Price} ₽")
                            .AppendText($"НДС: {supplierOffer.Vat}%");
                        }));
                    });
                }
            }));
        }