/// <summary> /// Defines page setup, headers, and footers. /// </summary> static void DefineContentSection(Document document, Project currentProject) { try { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.AddParagraph(currentProject.Name); header = section.Headers.EvenPage; header.AddParagraph(currentProject.Name); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); } catch (Exception ex) { throw ex; } }
/// <summary> /// Defines page setup, headers, and footers. /// </summary> private static void DefineContentSection(Document document, List<QueryData> data ) { Section section = document.AddSection(); //section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.AddParagraph(data[0].ProjectName + " - Отчет проверки данных от " + DateTime.Now.ToShortDateString() ); header.Format.Alignment = ParagraphAlignment.Center; // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); paragraph.AddText(" из "); paragraph.AddNumPagesField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); }
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; }
/// <summary> /// Defines page setup, headers, and footers. /// </summary> static void DefineContentSection(Document document, ArticlesWithWordMigra article) { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = false; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header.AddParagraph(article.EditionName +"\t"+ article.Url); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); }
void DefineRevisionHistory(Document document, string fontName, Color fontColor, List<RevisionHistory> listRevisionHistory) { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); section.Headers.Primary.Add(paragraph); section.Headers.EvenPage.Add(paragraph.Clone()); DocumentFormat.DefineHeading(document, "Revision History", "Heading1", "Revision History"); DocumentFormat.DefineParagraph(document, "", ParagraphAlignment.Center); string[] strArrayHeader = new string[4] { "Version", "Author", "Issue Date", "Changes" }; string[] strArrayHeaderSize = new string[4] { (PageWidth / 4).ToString() + "cm", (PageWidth / 4).ToString() + "cm", (PageWidth / 4).ToString() + "cm", (PageWidth / 4).ToString() + "cm" }; Table table = DocumentFormat.CreateSimpleTable(strArrayHeader, strArrayHeaderSize, DataStaging.GetStrMatrixFromListRevisionHistory(listRevisionHistory), FontName, Colors.Black, Colors.LightGray, 12, 0.5, 0.5, true); document.LastSection.Add(table); }
private void defineFooter() { Section section = document.AddSection(); section.PageSetup.OddAndEvenPagesHeaderFooter = true; section.PageSetup.StartingNumber = 1; HeaderFooter header = section.Headers.Primary; header = section.Headers.EvenPage; // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); // Add clone of paragraph to footer for odd pages. Cloning is necessary because an object must // not belong to more than one other object. If you forget cloning an exception is thrown. section.Footers.EvenPage.Add(paragraph.Clone()); }
public Document CreateDocument() { Document document = new Document(); document.Info.Title = "Existing Client Task List"; document.Info.Author = "Sol-TBCRM"; document.Info.Subject = ""; using (SqlConnection oConn = new SqlConnection(Connect.sConnStr)) { oConn.Open(); // Read the list of new clients string strQuery; if ((string)Session["LoggedInUserID"] == "7") strQuery = "select MarketerUserID, EventAssignedUserID, ClientID, MarketerName, MarketerSurname, users.sName as AssignedName, users.sSurname as AssignedSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, ClientID, users.sName as MarketerName, users.sSurname as MarketerSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, existing_clients.PKiClientID as ClientID, dtCreated, sMessage, existing_clients.sName as sClientName, existing_clients.sClientNumber, existing_clients.sContactPerson, existing_clients.sTelephone from (select marketer_assignment.FKiUserID as MarketerUserID, events.FKiExistingClientID as EventClientID, events.FKiUserAssignedID as EventAssignedUserID, events.dtCreated, events.sMessage from events inner join marketer_assignment on events.FKiExistingClientID = marketer_assignment.FKiClientID WHERE events.sStatus = 'Active') MarketerEventJoin inner join existing_clients on MarketerEventJoin.EventClientID = existing_clients.PKiClientID WHERE existing_clients.bExcluded = 0) MarketerEventsClientsJoin inner join users on users.PKiUserId = MarketerUserID) FinalJoin inner join users on PKiUserID = EventAssignedUserID ORDER BY MarketerUserID, ClientID, dtCreated"; else strQuery = "select MarketerUserID, EventAssignedUserID, ClientID, MarketerName, MarketerSurname, users.sName as AssignedName, users.sSurname as AssignedSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, ClientID, users.sName as MarketerName, users.sSurname as MarketerSurname, dtCreated, sMessage, sClientName, sClientNumber, sContactPerson, sTelephone from (select MarketerUserID, EventAssignedUserID, existing_clients.PKiClientID as ClientID, dtCreated, sMessage, existing_clients.sName as sClientName, existing_clients.sClientNumber, existing_clients.sContactPerson, existing_clients.sTelephone from (select marketer_assignment.FKiUserID as MarketerUserID, events.FKiExistingClientID as EventClientID, events.FKiUserAssignedID as EventAssignedUserID, events.dtCreated, events.sMessage from events inner join marketer_assignment on events.FKiExistingClientID = marketer_assignment.FKiClientID WHERE events.sStatus = 'Active' AND marketer_assignment.FKiUserID = '" + (string)Session["LoggedInUserID"] + "') MarketerEventJoin inner join existing_clients on MarketerEventJoin.EventClientID = existing_clients.PKiClientID WHERE existing_clients.bExcluded = 0) MarketerEventsClientsJoin inner join users on users.PKiUserId = MarketerUserID) FinalJoin inner join users on PKiUserID = EventAssignedUserID ORDER BY MarketerUserID, ClientID, dtCreated"; SqlDataReader reader = Connect.getDataCommand(strQuery, oConn).ExecuteReader(); int lastuserid = -1; int lastclientid = -1; int numclients = 0; int numevents = 0; DateTime lastdate = DateTime.MinValue; if (!reader.HasRows) { Section section = document.AddSection(); section.PageSetup.PageFormat = PageFormat.A4; section.AddParagraph("No items for user '" + (string)Session["LoggedInUserID"] + "'"); } while (reader.Read()) { // Start new section if ((int)reader["MarketerUserID"] != lastuserid) { /* if (lastuserid != -1) document.LastSection.AddPageBreak();*/ numclients = 0; lastuserid = (int)reader["MarketerUserID"]; // Create a paragraph with centered page number. See definition of style "Footer". Paragraph paragraph = new Paragraph(); paragraph.AddTab(); paragraph.AddPageField(); // Add a section to the document Section section = document.AddSection(); section.PageSetup.PageFormat = PageFormat.A4; section.PageSetup.StartingNumber = 1; // Add paragraph to footer for odd pages. section.Footers.Primary.Add(paragraph); HeaderFooter header = section.Headers.Primary; header.AddParagraph(DateTime.Now.ToString() + "\t\t" + (string)reader["MarketerName"] + " " + (string)reader["MarketerSurname"] + " Task List"); paragraph = section.AddParagraph(); paragraph.Format.Font.Name = "Arial"; paragraph.Format.Font.Size = Unit.FromPoint(18); paragraph.Format.SpaceBefore = Unit.FromCentimeter(2); paragraph.Format.SpaceAfter = Unit.FromCentimeter(2); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.AddText((string)reader["MarketerName"] + " " + (string)reader["MarketerSurname"] + " Task List\n"); Table table = section.AddTable(); table.Format.Alignment = ParagraphAlignment.Left; Column column = table.AddColumn(Unit.FromCentimeter(1)); table.AddColumn(Unit.FromCentimeter(2)); table.AddColumn(Unit.FromCentimeter(5)); table.AddColumn(Unit.FromCentimeter(5)); table.AddColumn(Unit.FromCentimeter(3)); Row row = table.AddRow(); row.Format.Font.Italic = true; row.Format.SpaceAfter = Unit.FromMillimeter(5); Cell cell = row.Cells[0]; cell.AddParagraph("#"); cell = row.Cells[1]; cell.AddParagraph("Code"); cell = row.Cells[2]; cell.AddParagraph("Client"); cell = row.Cells[3]; cell.AddParagraph("Contact"); cell = row.Cells[4]; cell.AddParagraph("Telephone"); numclients++; numevents = 1; lastclientid = (int)reader["ClientID"]; AddClient(document, reader, numclients); lastdate = (DateTime)reader["dtCreated"]; AddDate(document, reader); AddEvent(document, reader, numevents); } else // Continue in section { // New client if ((int)reader["ClientID"] != lastclientid) { lastclientid = (int)reader["ClientID"]; lastdate = (DateTime)reader["dtCreated"]; numclients++; numevents = 1; AddClient(document, reader, numclients); AddDate(document, reader); AddEvent(document, reader, numevents); } else // Continue with same client { DateTime newdate = (DateTime)reader["dtCreated"]; if (newdate.Year != lastdate.Year && newdate.Month != lastdate.Month && newdate.Day != lastdate.Day) // New date { AddDate(document, reader); numevents = 1; AddEvent(document, reader, numevents); } else // Continue with same date { numevents++; AddEvent(document, reader, numevents); } } } } reader.Close(); oConn.Close(); } return document; }
/// <summary> /// Defines page setup, headers, and footers /// </summary> /// <param name="document">MigraDoc document created via Documents.CreateDocument()</param> public static void DefineContentSection(Document document) { Section section = document.AddSection(); section.PageSetup.TopMargin = "5cm"; section.PageSetup.StartingNumber = 1; section.PageSetup.Orientation = Orientation.Landscape; // Create header HeaderFooter header = section.Headers.Primary; // Add logo Image image = header.AddImage(Report.logoPath); image.Width = "8cm"; image.WrapFormat.Style = WrapStyle.Through; // Add company name Paragraph h1 = new Paragraph(); h1.AddText(Report.companyName); h1.Format.Font.Color = Colors.SlateGray; h1.Format.Font.Size = 24; h1.Format.Font.Bold = true; header.Add(h1); // Add report name Paragraph h2 = new Paragraph(); h2.Format.Font.Color = Colors.SlateGray; h2.AddText("Welfare Check Breach Report"); h2.Format.Font.Size = 18; h2.Format.Borders.Width = 0; h2.Format.Borders.Bottom.Width = 1; h2.Format.Borders.Color = Colors.LightSlateGray; h2.Format.Borders.Distance = 4; header.Add(h2); // Add current date Paragraph h3 = new Paragraph(); h3.Format.Font.Size = 12; h3.Format.Font.Italic = true; h3.Format.Borders.Distance = 6; h3.AddDateField(); header.Add(h3); // Create a paragraph with centered page number. See definition of style "Footer". Paragraph footer = new Paragraph(); footer.Format.Borders.Width = 0; footer.Format.Borders.Top.Width = 1; footer.Format.Borders.Color = Colors.LightSlateGray; footer.Format.Borders.Distance = 10; footer.AddPageField(); // Add paragraph to footer section.Footers.Primary.Add(footer); }