/// <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); }
private void CreatePage() { // Each MigraDoc document needs at least one section. MigraDoc.DocumentObjectModel.Section section = this.document.AddSection(); // Put a logo in the header Image image = section.Headers.Primary.AddImage("Image_Icons/logo1.png"); image.Height = "2.5cm"; image.Width = "5cm"; image.LockAspectRatio = true; image.RelativeVertical = RelativeVertical.Line; image.RelativeHorizontal = RelativeHorizontal.Margin; image.Top = ShapePosition.Top; image.Left = ShapePosition.Right; image.WrapFormat.Style = WrapStyle.Through; // Create the text frame for the address this.addressFrame = section.AddTextFrame(); this.addressFrame.Height = "8.0cm"; this.addressFrame.Width = "10.0cm"; this.addressFrame.Left = ShapePosition.Left; this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin; this.addressFrame.Top = "4cm"; this.addressFrame.RelativeVertical = RelativeVertical.Page; this.PriceFrame = section.AddTextFrame(); this.PriceFrame.Height = "5.0cm"; this.PriceFrame.Width = "5.0cm"; this.PriceFrame.Left = ShapePosition.Right; this.PriceFrame.RelativeHorizontal = RelativeHorizontal.Margin; this.PriceFrame.Top = "4.0cm"; this.PriceFrame.RelativeVertical = RelativeVertical.Page; // Put sender in address frame //= addressFrame.AddParagraph("ul.Pralki 5, 13-342 Lodówka"); //paragraph.Format.Font.Name = "Times New Roman"; //paragraph.Format.Font.Size = 7; //paragraph.Format.SpaceAfter = 3; // Add the print date field MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph(); paragraph.Format.SpaceBefore = "8cm"; paragraph.Style = "Reference"; paragraph.AddFormattedText($"Faktura nr {order.Date.Year}/{order.Id}", TextFormat.Bold); paragraph.AddTab(); paragraph.AddText("Białystok, "); paragraph.AddDateField("dd.MM.yyyy"); paragraph = section.Footers.Primary.AddParagraph(); paragraph.AddText($"\u00a9 2021 RTV&AGD \n ul.Pralki 5, 13-342 Lodówka \n Data wydruku: {DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss")} "); paragraph.Format.Font.Size = 9; paragraph.Format.Alignment = ParagraphAlignment.Center; // Create the item table this.table = section.AddTable(); table.Format.Alignment = ParagraphAlignment.Justify; table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.Black; table.Borders.Width = 0.25; table.Borders.Left.Width = 0.5; table.Borders.Right.Width = 0.5; table.Rows.LeftIndent = 5; table.TopPadding = 10; table.BottomPadding = 10; // Before you can add a row, you must define the columns Column column = this.table.AddColumn("7.5cm"); column.Format.Alignment = ParagraphAlignment.Center; column = this.table.AddColumn("1.5cm"); column.Format.Alignment = ParagraphAlignment.Right; column = this.table.AddColumn("3.5cm"); column.Format.Alignment = ParagraphAlignment.Right; column = this.table.AddColumn("3.5cm"); column.Format.Alignment = ParagraphAlignment.Right; // Create the header of the table Row row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Left; row.Format.Font.Bold = true; row.Shading.Color = TableBlue; row.Cells[0].AddParagraph("Nazwa"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[0].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center; row.Cells[1].AddParagraph("Ilość"); row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Cells[2].AddParagraph("Cena/szt"); row.Cells[2].Format.Alignment = ParagraphAlignment.Left; row.Cells[2].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center; row.Cells[3].AddParagraph("Wartosc"); row.Cells[3].Format.Alignment = ParagraphAlignment.Left; row.Cells[3].VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center; this.table.SetEdge(0, 0, 4, 1, Edge.Box, BorderStyle.Single, 0.75, MigraDoc.DocumentObjectModel.Color.Empty); }
/// <summary> /// Creates the static parts of the invoice. /// </summary> void CreatePage() { // Each MigraDoc document needs at least one section. Section section = this.document.AddSection(); // Put a logo in the header Image image = section.AddImage(path); image.Top = ShapePosition.Top; image.Left = ShapePosition.Left; image.WrapFormat.Style = WrapStyle.Through; // Create footer Paragraph paragraph = section.Footers.Primary.AddParagraph(); paragraph.AddText("Health And Social Services."); paragraph.Format.Font.Size = 9; paragraph.Format.Alignment = ParagraphAlignment.Center; // Create the text frame for the address this.addressFrame = section.AddTextFrame(); this.addressFrame.Height = "3.0cm"; this.addressFrame.Width = "7.0cm"; this.addressFrame.Left = ShapePosition.Left; this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin; this.addressFrame.Top = "5.0cm"; this.addressFrame.RelativeVertical = RelativeVertical.Page; // Put sender in address frame paragraph = this.addressFrame.AddParagraph("Karachi,Pakistan"); paragraph.Format.Font.Name = "Times New Roman"; paragraph.Format.Font.Size = 7; paragraph.Format.SpaceAfter = 3; // Add the print date field paragraph = section.AddParagraph(); paragraph.Format.SpaceBefore = "6cm"; paragraph.Style = "Reference"; paragraph.AddFormattedText("Patients Detail", TextFormat.Bold); paragraph.AddTab(); paragraph.AddText("Date, "); paragraph.AddDateField("dd.MM.yyyy"); // Create the item table this.table = section.AddTable(); this.table.Style = "Table"; this.table.Borders.Color = TableBorder; this.table.Borders.Width = 0.25; this.table.Borders.Left.Width = 0.5; this.table.Borders.Right.Width = 0.5; this.table.Rows.LeftIndent = 0; // Before you can add a row, you must define the columns Column column; foreach (DataColumn col in dt.Columns) { column = this.table.AddColumn(Unit.FromCentimeter(3)); column.Format.Alignment = ParagraphAlignment.Center; } // Create the header of the table Row row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Shading.Color = TableBlue; for (int i = 0; i < dt.Columns.Count; i++) { row.Cells[i].AddParagraph(dt.Columns[i].ColumnName); row.Cells[i].Format.Font.Bold = false; row.Cells[i].Format.Alignment = ParagraphAlignment.Left; row.Cells[i].VerticalAlignment = VerticalAlignment.Bottom; } this.table.SetEdge(0, 0, dt.Columns.Count, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty); }