Пример #1
0
        private static Document CreatePDF(SetViewModel obj)
        {
            Document doc = new Document();

            //Defining styles
            Style style = doc.Styles["Normal"];
            style.Font.Name = "Arial";
            style.Font.Size = 6;

            style = doc.Styles[StyleNames.Header];
            style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right);

            style = doc.Styles[StyleNames.Footer];
            style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Right);

            foreach (var itemSet in obj.Set)
            {

                //Define content section
                Section section = doc.AddSection();
                section.PageSetup.StartingNumber = 1;
                section.PageSetup.LeftMargin = "0.7cm";
                section.PageSetup.RightMargin = "0.7cm";
                section.PageSetup.BottomMargin = "0.5cm";
                section.PageSetup.TopMargin = "1.4cm";
                section.PageSetup.FooterDistance = "0.5cm";
                section.PageSetup.HeaderDistance = "0.5cm";

                // Create Header
                Table hTable = section.Headers.Primary.AddTable();
                hTable.Borders.Width = 0;
                var hlColumn = hTable.AddColumn("6cm");
                hlColumn.Format.Alignment = ParagraphAlignment.Left;
                var hcColumn = hTable.AddColumn("8cm");
                hlColumn.Format.Alignment = ParagraphAlignment.Center;
                var hrColumn = hTable.AddColumn("6cm");
                hrColumn.Format.Alignment = ParagraphAlignment.Right;
                var hRow = hTable.AddRow();
                var hCell = hRow.Cells[0];
                hCell.AddParagraph("НИИ Антимикробной химиотерапии");
                hCell.Format.Alignment = ParagraphAlignment.Left;
                hCell = hRow.Cells[1];
                hCell.AddParagraph(itemSet.AB);
                hCell.Format.Alignment = ParagraphAlignment.Center;
                hCell = hRow.Cells[2];

                hCell.AddParagraph("Исследование " + itemSet.Project);
                hCell.Format.Alignment = ParagraphAlignment.Right;
                hRow = hTable.AddRow();
                hCell = hRow.Cells[0];
                hCell.AddParagraph("Метод тестирования: " + itemSet.TestMethod);
                hCell.Format.Alignment = ParagraphAlignment.Left;
                hCell = hRow.Cells[2];
                hCell.AddParagraph("Сет:  " + itemSet.Set + " - " + "Антибиотик: " + itemSet.AB);
                hCell.Format.Alignment = ParagraphAlignment.Right;
                hRow = hTable.AddRow();
                hCell = hRow.Cells[0];
                hCell.AddParagraph("Дата печати: " + DateTime.Now.ToShortDateString());
                hCell.Format.Alignment = ParagraphAlignment.Left;
                Paragraph fPar = new Paragraph();
                fPar.AddText("Страница ");
                fPar.AddPageField();
                fPar.AddText(" из ");
                fPar.AddSectionPagesField();
                hCell = hRow.Cells[2];
                hCell.Add(fPar);
                hCell.Format.Alignment = ParagraphAlignment.Right;

                hCell = hTable.Rows[0].Cells[1];
                hCell.MergeDown = 2;

                hCell.Format.Font.Bold = true;
                hCell.Format.Font.Size = 9;
                hCell.Format.Alignment = ParagraphAlignment.Center;

                // Create table

                Table table;
                Row row;
                Cell cell;
                CreateMicTable(doc, itemSet, section, out table, out row, out cell);

                foreach (var item in itemSet.MOList)
                {
                    row = table.AddRow();
                    row.Height = "0.55cm";
                    cell = row.Cells[0];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.Cell);
                    cell = row.Cells[1];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MuseumNumber);
                    cell = row.Cells[2];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MO);
                    if (item.Number % 12 == 0)
                    {
                        row.Borders.Bottom.Width = "0.05cm";
                    }
                    if ((item.Number % 48 == 0) && (item.Number > 10))
                    {
                        doc.LastSection.Add(table);
                        doc.LastSection.AddPageBreak();
                        CreateMicTable(doc, itemSet, section, out table, out row, out cell);

                    }
                }

                foreach (var item in itemSet.ControlMOList)
                {
                    row = table.AddRow();
                    row.Height = "0.5cm";
                    cell = row.Cells[0];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.Cell);
                    cell.Shading.Color = Colors.LightGray;
                    cell = row.Cells[1];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.AddParagraph(item.MuseumNumber);
                    cell.Shading.Color = Colors.LightGray;
                    cell = row.Cells[2];
                    cell.VerticalAlignment = VerticalAlignment.Center;
                    cell.Shading.Color = Colors.LightGray;
                    cell.AddParagraph(item.MO);

                }

                doc.LastSection.Add(table);

            }
            return doc;
        }