public Document CreateDocument(List <ProductDTO> dto, User.Model.User us, string name) { list = dto; // Create a new MigraDoc document this.document = new Document(); this.document.Info.Title = "A sample invoice"; this.document.Info.Subject = "Demonstrates how to create an invoice."; this.document.Info.Author = "Stefan Lange"; DefineStyles(); CreatePage(us, name); FillContent(); return(this.document); }
void CreatePage(User.Model.User user, string inv) { // Each MigraDoc document needs at least one section. Section section = this.document.AddSection(); // Create footer Paragraph paragraph = section.Footers.Primary.AddParagraph(); paragraph.AddText("Pizzeria \"Dobra Pizza\""); 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 = "3.0cm"; this.addressFrame.Left = ShapePosition.Right; this.addressFrame.RelativeHorizontal = RelativeHorizontal.Margin; this.addressFrame.Top = "2.0cm"; this.addressFrame.RelativeVertical = RelativeVertical.Page; //Create the text frame for user principles this.userFrame = section.AddTextFrame(); this.userFrame.Height = "3.0cm"; this.userFrame.Width = "7.0cm"; this.userFrame.Left = ShapePosition.Left; this.userFrame.RelativeHorizontal = RelativeHorizontal.Margin; this.userFrame.Top = "5.0cm"; this.userFrame.RelativeVertical = RelativeVertical.Page; // Put sender in address frame paragraph = this.addressFrame.AddParagraph($"Numer faktury:{inv} \r\n\r\nPizzeria \"Dobra Pizza\"\r\nAdres:\r\n"); paragraph.Format.Font.Name = "Times New Roman"; paragraph.Format.Font.Size = 7; paragraph.Format.SpaceAfter = 3; //Put some user info paragraph = this.userFrame.AddParagraph($"Klient:\r\n {user.name}\r\n{user.address}"); 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 = "8cm"; paragraph.Style = "Reference"; paragraph.AddFormattedText("Rachunek", TextFormat.Bold); paragraph.AddTab(); paragraph.AddText("Lodz, "); 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 = this.table.AddColumn("1cm"); column.Format.Alignment = ParagraphAlignment.Center; column = this.table.AddColumn("10cm"); column.Format.Alignment = ParagraphAlignment.Right; column = this.table.AddColumn("3cm"); 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.Center; row.Format.Font.Bold = true; row.Cells[0].AddParagraph("Nb."); row.Cells[0].Format.Font.Bold = false; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].AddParagraph("Nazwa"); row.Cells[1].Format.Alignment = ParagraphAlignment.Center; row.Cells[2].AddParagraph("Rozmiar"); row.Cells[2].Format.Alignment = ParagraphAlignment.Center; row.Cells[3].AddParagraph("Cena"); row.Cells[3].Format.Alignment = ParagraphAlignment.Center; table.SetEdge(0, 0, 4, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty); }