// [UnitTestFunction] public static void TestFields() { Document doc = new Document(); doc.Info.Author = "K.P."; Section sec = doc.Sections.AddSection(); Paragraph par = sec.AddParagraph(); par.AddBookmark("myBookmark1"); PageRefField prf = par.AddPageRefField("myBookmark1"); prf.Format = "ALPHABETIC"; PageField pf = par.AddPageField(); pf.Format = "ROMAN"; SectionField sf = par.AddSectionField(); sf.Format = "roman"; SectionPagesField spf = par.AddSectionPagesField(); spf.Format = "roman"; NumPagesField npf = par.AddNumPagesField(); npf.Format = "alphabetic"; InfoField inf = par.AddInfoField(InfoFieldType.Author); DateField df = par.AddDateField("D"); df = par.AddDateField("d"); df = par.AddDateField("s"); df = par.AddDateField("r"); df = par.AddDateField("G"); df = par.AddDateField("dddd dd.MM.yyyy"); DocumentRenderer docRndrr = new DocumentRenderer(); docRndrr.Render(doc, "RtfFields.txt", null); File.Copy("RtfFields.txt", "RtfFields.rtf", true); System.Diagnostics.Process.Start("RtfFields.txt"); }
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); }
private void AddSection(string sectionTitle, List <Book> sectionBooks) { var section = _document.AddSection(); var pageSetup = _document.DefaultPageSetup.Clone(); pageSetup.Orientation = Orientation.Landscape; pageSetup.StartingNumber = 1; pageSetup.TopMargin = Unit.FromInch(.4); pageSetup.BottomMargin = Unit.FromInch(.5); pageSetup.LeftMargin = Unit.FromInch(.7); pageSetup.RightMargin = Unit.FromInch(.4); pageSetup.FooterDistance = Unit.FromInch(.3); section.PageSetup = pageSetup; var paragraph = section.AddParagraph(sectionTitle); paragraph.Format.Font.Bold = true; paragraph.Format.Font.Size = Unit.FromPoint(16); var pageNumberParagraph = new Paragraph(); pageNumberParagraph.AddText($"{sectionTitle} - Page "); pageNumberParagraph.AddPageField(); pageNumberParagraph.AddText(" of "); pageNumberParagraph.AddSectionPagesField(); pageNumberParagraph.AddTab(); pageNumberParagraph.AddTab(); pageNumberParagraph.AddTab(); pageNumberParagraph.AddTab(); pageNumberParagraph.AddDateField(); section.Footers.Primary.Add(pageNumberParagraph); var table = new Table(); table.Borders.Width = 0.75; table.AddColumn(Unit.FromInch(.5)); table.AddColumn(Unit.FromInch(3)); table.AddColumn(Unit.FromInch(5.5)); table.AddColumn(Unit.FromInch(.5)); table.AddColumn(Unit.FromInch(1)); var row = table.AddRow(); row.HeadingFormat = true; row.Shading.Color = Colors.AntiqueWhite; var cell = row.Cells[0]; cell.AddParagraph("OK"); cell = row.Cells[1]; cell.AddParagraph("Author(s)"); cell = row.Cells[2]; cell.AddParagraph("Title(s)"); cell = row.Cells[3]; cell.AddParagraph("Mssng"); cell = row.Cells[4]; cell.AddParagraph("New Cat."); foreach (var book in sectionBooks) { row = table.AddRow(); row.Format.Font.Color = Colors.Black; row.Format.Font.Size = Unit.FromPoint(11); cell = row.Cells[1]; var par = cell.AddParagraph(book.GetAuthorDisplayName()); cell = row.Cells[2]; cell.AddParagraph(book.GetBookDisplayName()); } section.Add(table); }