public static void DemonstrateSimpleTable(Document document) { document.LastSection.AddParagraph("Simple Tables", "Heading2"); Table table = new Table(); table.Borders.Width = 0.75; Column column = table.AddColumn(Unit.FromCentimeter(2)); column.Format.Alignment = ParagraphAlignment.Center; table.AddColumn(Unit.FromCentimeter(5)); Row row = table.AddRow(); row.Shading.Color = Colors.PaleGoldenrod; Cell cell = row.Cells[0]; cell.AddParagraph("Itemus"); cell = row.Cells[1]; cell.AddParagraph("Descriptum"); row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("1"); cell = row.Cells[1]; cell.AddParagraph(FillerText.ShortText); row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph("2"); cell = row.Cells[1]; cell.AddParagraph(FillerText.Text); table.SetEdge(0, 0, 2, 3, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); document.LastSection.Add(table); }
public static Table CreateMergedDownTable(string[] strArrayHeader, string[] strArrayHeaderSize, string[][] strMatrixContent, int[][] matrixMergeDown, string fontName, Color fontColor, Color shadeColor, Unit fontSize, double borderSize, double edgeSize, bool isHeaderBold) { Table table = new Table(); table.Borders.Width = borderSize; for (int i = 0; i < strArrayHeader.GetLength(0); i++) { table.AddColumn(strArrayHeaderSize[i]); } Row row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = isHeaderBold; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; row.Shading.Color = shadeColor; row.VerticalAlignment = VerticalAlignment.Center; Cell cell; for (int i = 0; i < strArrayHeader.GetLength(0); i++) { cell = row.Cells[i]; cell.AddParagraph(strArrayHeader[i]); } for (int i = 0; i < strMatrixContent.GetLength(0); i++) { row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Left; row.Format.Font.Bold = false; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; string[] strArrayContent = strMatrixContent[i]; for (int j = 0; j < strArrayContent.GetLength(0); j++) { cell = row.Cells[j]; cell.MergeDown = matrixMergeDown[i][j]; if (strArrayContent[j].Contains(".jpg") || strArrayContent[j].Contains(".png")) { Image image = new Image(strArrayContent[j]); image.Width = strArrayHeaderSize[j]; cell.Add(image); } else { cell.AddParagraph(strArrayContent[j]); } } } table.SetEdge(0, 0, strArrayHeader.GetLength(0), strMatrixContent.GetLength(0) + 1, Edge.Box, BorderStyle.Single, edgeSize, Colors.Black); return table; }
private void SetTableHeader(ref Table table, Color tableColor) { var columns = new Dictionary<string, Dictionary<string, ParagraphAlignment>>(); columns.Add("#", new Dictionary<string, ParagraphAlignment> { {"1cm", ParagraphAlignment.Center} }); columns.Add("Title", new Dictionary<string, ParagraphAlignment> { {"6cm", ParagraphAlignment.Left} }); var taxesEnabled = _taxSettings.TaxesEnabled; var columnWidth = taxesEnabled ? "2cm" : "3cm"; columns.Add("Qty", new Dictionary<string, ParagraphAlignment> { {columnWidth, ParagraphAlignment.Center} }); columns.Add("Unit Price" + (taxesEnabled ? " (ex TAX)" : ""), new Dictionary<string, ParagraphAlignment> { {columnWidth, ParagraphAlignment.Right} }); if (taxesEnabled) { columns.Add("Tax Rate", new Dictionary<string, ParagraphAlignment> { {columnWidth, ParagraphAlignment.Right} }); } columns.Add("Net Sub Total", new Dictionary<string, ParagraphAlignment> { {"3cm", ParagraphAlignment.Right} }); foreach (var item in columns) { Column column = table.AddColumn(item.Value.First().Key); column.Format.Alignment = item.Value.First().Value; } Row row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Shading.Color = tableColor; row.TopPadding = 2; row.BottomPadding = 2; int rowId = 0; foreach (var item in columns) { row.Cells[rowId].AddParagraph(item.Key); row.Cells[rowId].Format.Alignment = ParagraphAlignment.Center; rowId++; } table.SetEdge(0, 0, 5, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty); }
private void SetTableData(Order order, ref Table table) { for (int i = 0; i < order.OrderLines.Count; i++) { OrderLine orderLine = order.OrderLines[i]; Row row = table.AddRow(); row.TopPadding = 2; row.BottomPadding = 2; var counter = 0; row.Cells[counter++].AddParagraph((i + 1).ToString()); row.Cells[counter++].AddParagraph(orderLine.Name); var quantity = orderLine.Quantity; row.Cells[counter++].AddParagraph(quantity.ToString()); var taxesEnabled = _taxSettings.TaxesEnabled; var unitPrice = (taxesEnabled ? orderLine.UnitPricePreTax : orderLine.UnitPrice); row.Cells[counter++].AddParagraph(unitPrice.ToCurrencyFormat()); if (taxesEnabled) { row.Cells[counter++].AddParagraph((orderLine.TaxRate) + "%"); } row.Cells[counter++].AddParagraph((unitPrice * quantity).ToCurrencyFormat()); table.SetEdge(0, table.Rows.Count - 2, 5, 2, Edge.Box, BorderStyle.Single, 0.75); } }
/// <summary> /// Erstellt aus einer DataTable eine Micradoc Tabelle /// </summary> /// <param name="dt">DataTable</param> /// <param name="columnWidths">Spaltenbreite</param> /// <param name="shadedColumns">Spalten mit Schattierung</param> /// <param name="stretchToPageWidth">Gibt an ob die Tabelle auf das gesamte Blatt gestretcht werden soll</param> /// <returns>Micradoc Tabelle</returns> protected Table GetTableFromDataTable(DataTable dt, List<int> columnWidths, List<int> shadedColumns, bool stretchToPageWidth) { Table table = new Table(); if (columnWidths != null) { foreach (int width in columnWidths) { table.AddColumn(new Unit((double)width, UnitType.Millimeter)); } } while (dt.Columns.Count > table.Columns.Count) { table.AddColumn(); } if (stretchToPageWidth) { double pageWidth = this.Document.LastSection.PageSetup.PageWidth.Millimeter - this.Document.LastSection.PageSetup.LeftMargin.Millimeter - this.Document.LastSection.PageSetup.RightMargin.Millimeter; double columnWidthSum = 0; foreach (Column column in table.Columns) { columnWidthSum += column.Width.Millimeter; } foreach (Column column in table.Columns) { column.Width = new Unit(column.Width.Millimeter * pageWidth / columnWidthSum, UnitType.Millimeter); if (!IsInvoice) { Border bor = new Border(); bor.Style = BorderStyle.Single; column.Borders.Left = bor; bor = new Border(); bor.Style = BorderStyle.Single; column.Borders.Right = bor; } } } var headerRow = table.AddRow(); headerRow.HeadingFormat = true; headerRow.Format.Font.Bold = true; int i = 0; foreach (DataColumn dc in dt.Columns) { headerRow[i].AddParagraph(dc.ColumnName); headerRow[i].Shading.Color = this.TableShadingColor; i++; } foreach (DataRow dr in dt.Rows) { var row = table.AddRow(dr.ItemArray); row.Height = new Unit((IsInvoice)?0.5:0.8, UnitType.Centimeter); if (!IsInvoice) { Border bor = new Border(); bor.Style = BorderStyle.Single; row.Borders.Left = bor; bor = new Border(); bor.Style = BorderStyle.Single; row.Borders.Right = bor; bor = new Border(); bor.Style = BorderStyle.Single; row.Borders.Bottom = bor; } foreach (int sc in shadedColumns) { row[sc].Shading.Color = this.TableShadingColor; } } table.SetEdge(0, 0, table.Columns.Count, 1, Edge.Box, BorderStyle.Single, new Unit(1, UnitType.Point)); table.SetEdge(0, 1, table.Columns.Count, table.Rows.Count - 1, Edge.Box, BorderStyle.Single, new Unit(1, UnitType.Point)); return table; }
public IActionResult OnGet(string pdf) { //get the session first! UserName = HttpContext.Session.GetString(SessionKeyName1); FirstName = HttpContext.Session.GetString(SessionKeyName2); SessionID = HttpContext.Session.GetString(SessionKeyName3); DatabaseConnect dbstring = new DatabaseConnect(); //creating an object from the class string DbConnection = dbstring.DatabaseString(); //calling the method from the class Console.WriteLine(DbConnection); SqlConnection conn = new SqlConnection(DbConnection); conn.Open(); using (SqlCommand command = new SqlCommand()) { command.Connection = conn; command.CommandText = @"SELECT EmployeeID, EmpFName + ' ' + EmpLName AS EmployeeName, EmpDoB AS EmployeeBornOn, EmpHireDate AS EmployedOn FROM EmployeesTable;"; var reader = command.ExecuteReader(); Employee = new List <Employee>(); while (reader.Read()) { Employee Row = new Employee(); //each record found from the table Row.EmployeeId = reader.GetInt32(0); Row.EmployeeFirstName = reader.GetString(1); Row.EmployeeDoB = reader.GetDateTime(2); Row.EmployeeDateHired = reader.GetDateTime(3); Employee.Add(Row); } } //PDF code here! if (pdf == "1") { //Create an object for pdf document Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); para.Format.Font.Name = "Arial"; para.Format.Font.Size = 14; para.Format.Font.Color = Color.FromCmyk(0, 0, 0, 100); //black colour para.AddFormattedText("List of Employees", TextFormat.Bold); para.Format.SpaceAfter = "1.0cm"; para.AddFormattedText(); //Table Table tab = new Table(); tab.Borders.Width = 0.75; tab.TopPadding = 5; tab.BottomPadding = 5; //Column Column col = tab.AddColumn(Unit.FromCentimeter(3)); col.Format.Alignment = ParagraphAlignment.Center; tab.AddColumn(Unit.FromCentimeter(3)); tab.AddColumn(Unit.FromCentimeter(3)); tab.AddColumn(Unit.FromCentimeter(3)); //tab.AddColumn(Unit.FromCentimeter(3)); //Row Row row = tab.AddRow(); row.Shading.Color = Colors.Coral;//select your preference colour! //Cell for header Cell cell = new Cell(); cell = row.Cells[0]; cell.AddParagraph("EmployeeID"); cell = row.Cells[1]; cell.AddParagraph("Employee First Name"); cell = row.Cells[2]; cell.AddParagraph("Employee Date of Birth"); cell = row.Cells[3]; cell.AddParagraph("Employee Hire Date"); //Add data to table for (int i = 0; i < Employee.Count; i++) { row = tab.AddRow(); cell = row.Cells[0]; cell.AddParagraph(Convert.ToString(i + 1)); cell = row.Cells[1]; cell.AddParagraph(Employee[i].EmployeeFirstName); cell = row.Cells[2]; cell.AddParagraph(Convert.ToString(Employee[i].EmployeeDateHired)); cell = row.Cells[3]; cell.AddParagraph(Convert.ToString(Employee[i].EmployeeDoB)); } tab.SetEdge(0, 0, 4, (Employee.Count + 1), Edge.Box, BorderStyle.Single, 1.5, Colors.Black); sec.Add(tab); //Rendering PdfDocumentRenderer pdfRen = new PdfDocumentRenderer(); pdfRen.Document = doc; pdfRen.RenderDocument(); //Create a memory stream MemoryStream stream = new MemoryStream(); pdfRen.PdfDocument.Save(stream); //saving the file into the stream Response.Headers.Add("content-disposition", new[] { "inline; filename = ListofEmployees.pdf" }); return(File(stream, "application/pdf")); } return(Page()); }
/// <summary> /// Adds the invoice items to the table /// </summary> /// <param name="table"></param> private void PopulateTable(Table table) { // Iterate the invoice items decimal totalExtendedPrice = 0; foreach (var item in CompanyInvoiceItems) { // Each item fills two rows Row r = table.AddRow(); r.TopPadding = 1.5; r.Cells[0].Format.Alignment = ParagraphAlignment.Left; r.Cells[1].Shading.Color = Colors.LightGray; r.Cells[0].AddParagraph(item.description); var paragraph = r.Cells[1].AddParagraph(); paragraph.AddFormattedText(String.Format("{0:C}",item.cost), TextFormat.Bold); totalExtendedPrice += item.cost; table.SetEdge(0, table.Rows.Count - 1, 2, 1, Edge.Box, BorderStyle.Single, 0.75); } // Add an invisible row as a space line to the table Row row = table.AddRow(); row.Borders.Visible = false; // Add the total price row row = table.AddRow(); row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph("Total Price"); row.Cells[0].Format.Font.Bold = true; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[1].AddParagraph(String.Format("{0:C}", totalExtendedPrice)); // Set the borders of the specified cell range table.SetEdge(1, table.Rows.Count - 1, 1, 1, Edge.Box, BorderStyle.Single, 0.75); }
private void HeaderRows(Table table, bool useName, bool useDate) { var row = table.AddRow(); row.Height = "1cm"; row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Shading.Color = Colors.LightGray; row.Cells[0].AddParagraph(useName ? "Product" : useDate ? "Date" : "Location"); row.Cells[0].Format.Alignment = ParagraphAlignment.Center; row.Cells[0].VerticalAlignment = VerticalAlignment.Center; row.Cells[1].AddParagraph("Vendor"); row.Cells[1].Format.Alignment = ParagraphAlignment.Center; row.Cells[1].VerticalAlignment = VerticalAlignment.Center; row.Cells[2].AddParagraph("Unit Price"); row.Cells[2].Format.Alignment = ParagraphAlignment.Center; row.Cells[2].VerticalAlignment = VerticalAlignment.Center; row.Cells[3].AddParagraph("Quantity"); row.Cells[3].Format.Alignment = ParagraphAlignment.Center; row.Cells[3].VerticalAlignment = VerticalAlignment.Center; row.Cells[4].AddParagraph("Sum"); row.Cells[4].Format.Alignment = ParagraphAlignment.Center; row.Cells[4].VerticalAlignment = VerticalAlignment.Center; table.SetEdge(0, 0, 5, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty); }
public static Table CreateSimpleMatrix(string[] strArrayHeaderHorizontal, string[] strArrayHeaderVertical, string strHeaderSize, string[] strArrayHeaderSize, string[][] strMatrixContent, string fontName, Color fontColor, Color shadeColor, Unit fontSize, double borderSize, double edgeSize, bool isHeaderBold) { Table table = new Table(); table.Borders.Width = borderSize; Column column = table.AddColumn(strHeaderSize); column.Format.Alignment = ParagraphAlignment.Center; column.Format.Font.Bold = true; column.Format.Font.Name = fontName; column.Format.Font.Color = fontColor; column.Format.Font.Size = fontSize; column.Shading.Color = shadeColor; for (int i = 0; i < strArrayHeaderHorizontal.GetLength(0); i++) { table.AddColumn(strArrayHeaderSize[i]); } Row row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = isHeaderBold; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; row.Shading.Color = shadeColor; row.VerticalAlignment = VerticalAlignment.Center; Cell cell; for (int i = 0; i < strArrayHeaderHorizontal.GetLength(0) + 1; i++) { cell = row.Cells[i]; if (i == 0) { cell.Shading.Color = Colors.Black; } else { cell.AddParagraph(strArrayHeaderHorizontal[i - 1]); } } for (int i = 0; i < strMatrixContent.GetLength(0); i++) { row = table.AddRow(); row.Format.Alignment = ParagraphAlignment.Left; row.Format.Font.Bold = false; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; string[] strArrayContent = strMatrixContent[i]; for (int j = 0; j < strArrayContent.GetLength(0) + 1; j++) { cell = row.Cells[j]; if (j == 0) { cell.AddParagraph(strArrayHeaderVertical[i]); } else { cell.AddParagraph(strArrayContent[j - 1]); } } } table.SetEdge(0, 0, strArrayHeaderHorizontal.GetLength(0) + 1, strMatrixContent.GetLength(0) + 1, Edge.Box, BorderStyle.Single, edgeSize, Colors.Black); return table; }
public static Table CreateSimpleTableWithoutHeader(string[] strArrayColumnSize, string[][] strMatrixContent, string fontName, Color fontColor, Unit fontSize, double borderSize, double edgeSize, ParagraphAlignment alignment) { Table table = new Table(); table.Borders.Width = borderSize; for (int i = 0; i < strArrayColumnSize.GetLength(0); i++) { table.AddColumn(strArrayColumnSize[i]); } Row row; Cell cell; for (int i = 0; i < strMatrixContent.GetLength(0); i++) { row = table.AddRow(); row.Format.Alignment = alignment; row.Format.Font.Bold = false; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; string[] strArrayContent = strMatrixContent[i]; for (int j = 0; j < strArrayContent.GetLength(0); j++) { cell = row.Cells[j]; if (strArrayContent[j].Contains(".jpg") || strArrayContent[j].Contains(".png")) { Image image = new Image(strArrayContent[j]); image.Width = strArrayColumnSize[j]; cell.Add(image); } else { cell.AddParagraph(strArrayContent[j]); } } } table.SetEdge(0, 0, strArrayColumnSize.GetLength(0), strMatrixContent.GetLength(0), Edge.Box, BorderStyle.Single, edgeSize, Colors.Black); return table; }
static void exportPDF(List<string> students, List<string> info, List<string> rubrik) { SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "PDF File (*.pdf|*.pdf"; if (saveFile.ShowDialog() != DialogResult.OK) return; Document doc = new Document(); string assignmentName = info[0]; string courseCode = info[1]; string prof = info[2]; string ta = info[3]; //MetaData doc.Info.Title = assignmentName + " Cover Page Print-Outs " + courseCode; doc.Info.Author = "Tyler Wilding"; //Document Styles Style style = doc.Styles["Normal"]; style.Font.Name = "Segoe UI"; style.Font.Size = 12; style = doc.Styles["Heading1"]; style.Font.Name = "Segoe UI"; style.Font.Size = 24; style.Font.Color = Colors.Black; style.Font.Bold = true; style = doc.Styles["Heading2"]; style.Font.Name = "Segoe UI"; style.Font.Size = 18; style.Font.Color = Colors.DarkMagenta; style = doc.Styles.AddStyle("Small", "Normal"); style.Font.Name = "Segoe UI"; style.Font.Size = 10; style.Font.Color = Colors.Black; style.Font.Italic = true; foreach (string student in students) { //Front Cover Section section = doc.AddSection(); Paragraph paragraph = section.AddParagraph(student); paragraph.Format.SpaceAfter = "3.5cm"; paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Style = "Heading1"; paragraph = section.AddParagraph(courseCode); paragraph.Format.SpaceAfter = "2.5cm"; paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Style = "Heading2"; paragraph = section.AddParagraph(assignmentName); paragraph.Format.SpaceAfter = "2.5cm"; paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Style = "Heading2"; paragraph = section.AddParagraph("Professor: " + prof); paragraph.Format.SpaceAfter = "2.5cm"; paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Style = "Heading2"; paragraph = section.AddParagraph("Teaching Assistant: " + ta); paragraph.Format.SpaceAfter = "2.5cm"; paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Style = "Heading2"; section.AddPageBreak(); //Marking Breakdown paragraph = section.AddParagraph("Marking Breakdown"); paragraph.Format.Alignment = ParagraphAlignment.Center; paragraph.Format.SpaceAfter = "0.25cm"; paragraph.Style = "Heading2"; Table table = new Table(); table.Rows.Alignment = RowAlignment.Center; table.Borders.Width = 0.75; table.AddColumn(Unit.FromCentimeter(8)); Column column = table.AddColumn(Unit.FromCentimeter(2)); column.Format.Alignment = ParagraphAlignment.Right; Row row = table.AddRow(); row.Shading.Color = Colors.PaleGreen; row.Style = "Normal"; Cell cell = row.Cells[0]; paragraph = section.AddParagraph(); cell.AddParagraph("Programming Questions"); cell = row.Cells[1]; cell.AddParagraph(rubrik[0] + "%"); row = table.AddRow(); row.Shading.Color = Colors.PaleGreen; row.Style = "Normal"; cell = row.Cells[0]; cell.AddParagraph("Demonstration"); cell = row.Cells[1]; cell.AddParagraph(rubrik[1] + "%"); row = table.AddRow(); row.Shading.Color = Colors.PaleVioletRed; row.Style = "Normal"; cell = row.Cells[0]; cell.AddParagraph("Comment Deduction"); cell = row.Cells[1]; cell.AddParagraph(rubrik[2] + "%"); row = table.AddRow(); row.Shading.Color = Colors.PaleVioletRed; row.Style = "Normal"; cell = row.Cells[0]; cell.AddParagraph("Formatting Deduction"); cell = row.Cells[1]; cell.AddParagraph(rubrik[3] + "%"); row = table.AddRow(); row.Shading.Color = Colors.PaleVioletRed; row.Style = "Normal"; cell = row.Cells[0]; cell.AddParagraph("Late Penalty"); cell = row.Cells[1]; cell.AddParagraph(rubrik[4] + "%"); table.SetEdge(0, 0, 2, 3, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, 1.5, Colors.Black); table.Format.SpaceAfter = "1.5cm"; section.Add(table); //Programming Problems paragraph = section.AddParagraph("Programming Problems"); paragraph.Style = "Heading1"; paragraph.Format.SpaceAfter = "0.25cm"; for(int i = 5; i < rubrik.Count; i+=2) { paragraph = section.AddParagraph(rubrik[i]+" (\t\t/"+rubrik[i+1]+")"); paragraph.Style = "Heading2"; paragraph.Format.LeftIndent = "1cm"; paragraph = section.AddParagraph("Notes: "); paragraph.Style = "Normal"; paragraph.Format.SpaceAfter = "1cm"; paragraph.Format.LeftIndent = "2cm"; } paragraph = section.AddParagraph("Demonstration " + "(\t\t/" + rubrik[1]+")"); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.Style = "Heading1"; paragraph = section.AddParagraph("Notes: "); paragraph.Style = "Normal"; paragraph.Format.SpaceAfter = "2cm"; paragraph.Format.LeftIndent = "1cm"; paragraph = section.AddParagraph("Comment Deduction " + "(\t\t/" + rubrik[2] + ")"); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.Style = "Heading1"; paragraph = section.AddParagraph("Notes: "); paragraph.Style = "Normal"; paragraph.Format.SpaceAfter = "2cm"; paragraph.Format.LeftIndent = "1cm"; paragraph = section.AddParagraph("Formatting Deduction " + "(\t\t/" + rubrik[3] + ")"); paragraph.Format.Alignment = ParagraphAlignment.Left; paragraph.Style = "Heading1"; paragraph = section.AddParagraph("Notes: "); paragraph.Style = "Normal"; paragraph.Format.SpaceAfter = "2cm"; paragraph.Format.LeftIndent = "1cm"; } //Setting Up Exporting MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(doc, "MigraDoc.mddd1"); PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = doc; renderer.RenderDocument(); //Name of document string filename = saveFile.FileName; renderer.PdfDocument.Save(filename); Process.Start(filename); }
private static void SimpleTable(Document document, QueryData data) { document.LastSection.AddParagraph("Описание: " + data.Description, "Heading2"); Table table = new Table(); table.Borders.Width = 0.75; Row row ; Cell cell; int i = 0; int cntr = 0; foreach (var strFieldName in data.FieldsName) { var column = table.AddColumn(); column.Format.Alignment = ParagraphAlignment.Center; column.Width = (document.DefaultPageSetup.PageWidth - document.DefaultPageSetup.RightMargin - document.DefaultPageSetup.LeftMargin)/data.FieldsName.Count; } row = table.AddRow(); row.Shading.Color = Colors.PaleGoldenrod; row.HeadingFormat = true; foreach (var strFieldName in data.FieldsName) { cell = row.Cells[i]; cell.AddParagraph(strFieldName); i++; } for ( i = 0; i < data.Data.Rows.Count; i++) { cntr++; row = table.AddRow(); if (cntr % 2 == 0) { row.Shading.Color = Colors.LightGray; } for (int j = 0; j < data.FieldsName.Count; j++) { cell = row.Cells[j]; cell.AddParagraph(data.Data.Rows[i][j].ToString()); cell.Format.Font.Size = 8; } } table.SetEdge(0, 0, data.FieldsName.Count, data.Data.Rows.Count, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); document.LastSection.Add(table); }
public static void CreateHeader(Document document) { MigraDoc.DocumentObjectModel.Tables.Table header = new MigraDoc.DocumentObjectModel.Tables.Table(); header.Shading.Color = Colors.MidnightBlue; header.Format.Font.Color = Colors.White; header.Format.Alignment = ParagraphAlignment.Center; header.Format.Font.Bold = true; Column h_column = header.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(4)); h_column.Format.Alignment = ParagraphAlignment.Center; h_column = header.AddColumn("2.5cm"); h_column.Format.Alignment = ParagraphAlignment.Center; h_column = header.AddColumn("2.5cm"); h_column.Format.Alignment = ParagraphAlignment.Center; h_column = header.AddColumn("2.5cm"); h_column.Format.Alignment = ParagraphAlignment.Center; h_column = header.AddColumn("2.5cm"); h_column.Format.Alignment = ParagraphAlignment.Center; h_column = header.AddColumn("2.5cm"); h_column.Format.Alignment = ParagraphAlignment.Center; Row h_row = header.AddRow(); Cell h_cell = h_row.Cells[5]; h_row = header.AddRow(); h_cell = h_row.Cells[0]; h_row.Cells[0].MergeDown = 2; h_cell.AddImage(HttpContext.Current.Server.MapPath("~/img/pmm-mini.png")).Width = "3.5cm"; h_cell = h_row.Cells[1]; h_cell.VerticalAlignment = VerticalAlignment.Top; h_cell.AddParagraph("Datos del Transporte"); h_row.Cells[1].MergeRight = 4; h_row = header.AddRow(); h_row.HeadingFormat = true; h_row.Format.Font.Size = 6; h_row.VerticalAlignment = VerticalAlignment.Top; h_cell = h_row.Cells[1]; h_cell.AddParagraph("Código del Formato:"); h_cell = h_row.Cells[2]; h_cell.AddParagraph("Fecha de Efectividad:"); h_cell = h_row.Cells[3]; h_cell.AddParagraph("Tiempo de Retención:"); h_cell = h_row.Cells[4]; h_cell.AddParagraph("Versión:"); h_cell = h_row.Cells[5]; h_cell.AddParagraph("Página:"); h_row = header.AddRow(); h_row.Format.Font.Size = 6; h_cell = h_row.Cells[1]; h_cell.AddParagraph("QM0474.F01"); h_cell = h_row.Cells[2]; h_cell.AddParagraph(DateTime.Now.ToString()); h_cell = h_row.Cells[3]; h_cell.AddParagraph(""); h_cell = h_row.Cells[4]; h_cell.AddParagraph("1.0"); h_cell = h_row.Cells[5]; h_cell.AddParagraph("1 de 1"); header.SetEdge(0, 0, 6, 4, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, .5, Colors.Black); document.LastSection.Add(header); }
public static void CreatePage(Document document, Ventana ventana) { MigraDoc.DocumentObjectModel.Tables.Table table = new MigraDoc.DocumentObjectModel.Tables.Table(); table.Borders.Width = 0.5; Column column = table.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(4)); column.Format.Alignment = ParagraphAlignment.Left; table.AddColumn(MigraDoc.DocumentObjectModel.Unit.FromCentimeter(12.5)); Row row = table.AddRow(); row.Shading.Color = Colors.White; Cell cell = row.Cells[0]; row.Cells[0].MergeRight = 1; row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("PO:"); cell = row.Cells[1]; cell.AddParagraph(ventana.PO); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Recursos:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Recurso); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Cantidades (#pp):"); cell = row.Cells[1]; cell.AddParagraph(ventana.Cantidad); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Linea Transportista:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Carrier.NombreCorto); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Operador:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Conductor); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Movil:"); cell = row.Cells[1]; cell.AddParagraph(ventana.MovilConductor); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Origen:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Procedencia.NombreCorto); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Destino:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Destino.NombreCorto); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Fecha:"); cell = row.Cells[1]; cell.AddParagraph((ventana.Evento.FechaInicio).ToString()); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("No ECO Tractor:"); cell = row.Cells[1]; cell.AddParagraph(ventana.NumeroEconomico); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Placas Tractor:"); cell = row.Cells[1]; cell.AddParagraph(ventana.NumeroPlaca); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("No Caja/Contenedor:"); cell = row.Cells[1]; cell.AddParagraph(ventana.EconomicoRemolque); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Placas Caja/Contenedor:"); cell = row.Cells[1]; cell.AddParagraph(ventana.PlacaRemolque); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Modelo:"); cell = row.Cells[1]; cell.AddParagraph(ventana.ModeloContenedor); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Color:"); cell = row.Cells[1]; cell.AddParagraph(ventana.ColorContenedor); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Tipo Unidad:"); cell = row.Cells[1]; cell.AddParagraph(ventana.TipoUnidad); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Dimensión:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Dimension); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Sellos:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Sellos); row = table.AddRow(); row.Format.Font.Size = 6; cell = row.Cells[0]; cell.AddParagraph("Temperatura Controlada:"); cell = row.Cells[1]; cell.AddParagraph(ventana.Temperatura); table.SetEdge(0, 0, 2, 20, Edge.Box, MigraDoc.DocumentObjectModel.BorderStyle.Single, .5, Colors.Black); document.LastSection.Add(table); }
/// <summary> /// Adds learning data /// </summary> /// <param name="document">Document - pdf document</param> /// <param name="mat">MatrixMB - matrix object</param> private static void AddMatrixTable(Document document, LearnByErrorLibrary.MatrixMB mat) { try { var name = "Dane wejściowe" + " " + (mat.Name != "" ? " - " + mat.Name : ""); Paragraph paragraph = document.LastSection.AddParagraph(name, "Heading2"); paragraph.AddBookmark("Dane wejściowe"); Table table = new Table(); table.Borders.Width = 0.75; for (int col = 0; col < mat.Cols; col++) { Column column = table.AddColumn(Unit.FromCentimeter(1.5)); column.Format.Alignment = ParagraphAlignment.Center; } for (int r = 0; r < mat.Rows; r++) { Row row = table.AddRow(); row.Shading.Color = r % 2 == 0 ? Colors.LightGray : Colors.LightBlue; for (int c = 0; c < mat.Cols; c++) { Cell cell = row.Cells[c]; cell.AddParagraph(mat.Data[r][c].ToString()); } } table.SetEdge(0, 0, mat.Cols, mat.Rows, Edge.Box, BorderStyle.Single, 0.5, Colors.Black); document.LastSection.Add(table); } catch (Exception ex) { ex.ToLog(); } }
private void SetTableSummary(Order order, ref Table table) { var summaryData = new Dictionary<string, string>(); var subtotal = _taxSettings.TaxesEnabled ? order.Subtotal : order.Total - order.ShippingTotal; summaryData.Add("Sub-total", subtotal.ToCurrencyFormat()); var shipping = _taxSettings.TaxesEnabled && _taxSettings.ShippingRateTaxesEnabled ? (order.ShippingSubtotal - order.ShippingTax) : order.ShippingSubtotal; summaryData.Add("Shipping", shipping.ToCurrencyFormat()); if (_taxSettings.TaxesEnabled) { summaryData.Add("Tax", order.Tax.ToCurrencyFormat()); } summaryData.Add("Discount", order.DiscountAmount.ToCurrencyFormat()); summaryData.Add("Total", order.Total.ToCurrencyFormat()); var startIndex = _taxSettings.TaxesEnabled ? 5 : 4; foreach (var item in summaryData) { Row row = table.AddRow(); row.TopPadding = 2; row.BottomPadding = 2; row.Cells[0].Borders.Visible = false; row.Cells[0].AddParagraph(item.Key + ":"); row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[0].MergeRight = startIndex - 1; if (item.Key == "Total") row.Cells[startIndex].Format.Font.Bold = true; row.Cells[startIndex].AddParagraph(item.Value); } table.SetEdge(startIndex, table.Rows.Count - 3, 1, 3, Edge.Box, BorderStyle.Single, 0.75); }
public static void DrawGrid(Section section,ODGrid grid) { //first, calculate width of dummy column that will push the grid over just enough to center it on the page. double pageW=0; if(CultureInfo.CurrentCulture.Name=="en-US") { pageW=850; } //don't know about Canada else { pageW=830; } //in 100ths/inch double widthAllColumns=(double)grid.WidthAllColumns/.96; double lmargin=section.Document.DefaultPageSetup.LeftMargin.Inch*100; double dummyColW=(pageW-widthAllColumns)/2-lmargin; Table table=new Table(); Column col; col=table.AddColumn(Unit.FromInch(dummyColW/100)); for(int i=0;i<grid.Columns.Count;i++){ col=table.AddColumn(Unit.FromInch((double)grid.Columns[i].ColWidth/96)); col.LeftPadding=Unit.FromInch(.01); col.RightPadding=Unit.FromInch(.01); } Row row; row=table.AddRow(); row.HeadingFormat=true; row.TopPadding=Unit.FromInch(0); row.BottomPadding=Unit.FromInch(-.01); Cell cell; Paragraph par; //dummy column: cell=row.Cells[0]; //cell.Shading.Color=Colors.LightGray; //format dummy cell? MigraDoc.DocumentObjectModel.Font fontHead=new MigraDoc.DocumentObjectModel.Font("Arial",Unit.FromPoint(8.5)); fontHead.Bold=true; for(int i=0;i<grid.Columns.Count;i++){ cell = row.Cells[i+1]; par=cell.AddParagraph(); par.AddFormattedText(grid.Columns[i].Heading,fontHead); par.Format.Alignment=ParagraphAlignment.Center; cell.Format.Alignment=ParagraphAlignment.Center; cell.Borders.Width=Unit.FromPoint(1); cell.Borders.Color=Colors.Black; cell.Shading.Color=Colors.LightGray; } MigraDoc.DocumentObjectModel.Font fontBody=null;//=new MigraDoc.DocumentObjectModel.Font("Arial",Unit.FromPoint(8.5)); bool isBold; System.Drawing.Color color; int edgeRows=1; for(int i=0;i<grid.Rows.Count;i++,edgeRows++){ row=table.AddRow(); row.TopPadding=Unit.FromInch(.01); row.BottomPadding=Unit.FromInch(0); for(int j=0;j<grid.Columns.Count;j++){ cell = row.Cells[j+1]; par=cell.AddParagraph(); if(grid.Rows[i].Cells[j].Bold==YN.Unknown){ isBold=grid.Rows[i].Bold; } else if(grid.Rows[i].Cells[j].Bold==YN.Yes){ isBold=true; } else{// if(grid.Rows[i].Cells[j].Bold==YN.No){ isBold=false; } if(grid.Rows[i].Cells[j].ColorText==System.Drawing.Color.Empty){ color=grid.Rows[i].ColorText; } else{ color=grid.Rows[i].Cells[j].ColorText; } fontBody=CreateFont(8.5f,isBold,color); par.AddFormattedText(grid.Rows[i].Cells[j].Text,fontBody); if(grid.Columns[j].TextAlign==HorizontalAlignment.Center){ cell.Format.Alignment=ParagraphAlignment.Center; } if(grid.Columns[j].TextAlign==HorizontalAlignment.Left) { cell.Format.Alignment=ParagraphAlignment.Left; } if(grid.Columns[j].TextAlign==HorizontalAlignment.Right) { cell.Format.Alignment=ParagraphAlignment.Right; } cell.Borders.Color=new MigraDoc.DocumentObjectModel.Color(180,180,180); if(grid.Rows[i].ColorLborder!=System.Drawing.Color.Empty){ cell.Borders.Bottom.Color=ConvertColor(grid.Rows[i].ColorLborder); } } if(grid.Rows[i].Note!=null && grid.Rows[i].Note!="" && grid.NoteSpanStop>0 && grid.NoteSpanStart<grid.Columns.Count){ row=table.AddRow(); row.TopPadding=Unit.FromInch(.01); row.BottomPadding=Unit.FromInch(0); cell=row.Cells[grid.NoteSpanStart+1]; par=cell.AddParagraph(); par.AddFormattedText(grid.Rows[i].Note,fontBody); cell.Format.Alignment=ParagraphAlignment.Left; cell.Borders.Color=new MigraDoc.DocumentObjectModel.Color(180,180,180); cell.MergeRight=grid.Columns.Count-1-grid.NoteSpanStart; edgeRows++; } } table.SetEdge(1,0,grid.Columns.Count,edgeRows,Edge.Box,MigraDoc.DocumentObjectModel.BorderStyle.Single,1,Colors.Black); section.Add(table); }
public static void DemonstrateSimpleTable(Document document) { var table = new Table(); table.Borders.Width = 0.25; Column column = table.AddColumn(Unit.FromCentimeter(2)); column.Format.Alignment = ParagraphAlignment.Center; table.AddColumn(Unit.FromCentimeter(2)); table.AddColumn(Unit.FromCentimeter(4)); table.AddColumn(Unit.FromCentimeter(4)); table.AddColumn(Unit.FromCentimeter(2)); table.AddColumn(Unit.FromCentimeter(2)); table.AddColumn(Unit.FromCentimeter(2)); Row row = table.AddRow(); row.Shading.Color = Colors.PaleGoldenrod; Cell cell = row.Cells[0]; cell.AddParagraph("Status"); cell = row.Cells[1]; cell.AddParagraph("Category"); cell = row.Cells[2]; cell.AddParagraph("Title"); cell = row.Cells[3]; cell.AddParagraph("Description"); cell = row.Cells[4]; cell.AddParagraph("Creator Name"); cell = row.Cells[5]; cell.AddParagraph("Size"); cell = row.Cells[6]; cell.AddParagraph("Download Date"); var rowCount = 0; try { using (var conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["oktrackerConnectionString"].ConnectionString)) { conn.Open(); var command = conn.CreateCommand(); command.CommandType = CommandType.StoredProcedure; command.CommandText = "history_of_user"; command.Parameters.Add(new MySqlParameter("p_user_id", MySqlDbType.Int32)); command.Parameters["p_user_id"].Value = (int) HttpContext.Current.Session["uid"]; using (var reader = command.ExecuteReader()) { while (reader.Read()) { row = table.AddRow(); cell = row.Cells[0]; cell.AddParagraph(reader.GetString("status_name")); cell = row.Cells[1]; cell.AddParagraph(reader.GetString("category_name")); cell = row.Cells[2]; cell.AddParagraph(reader.GetString("release_title")); cell = row.Cells[3]; cell.AddParagraph(reader.GetString("release_description")); cell = row.Cells[4]; cell.AddParagraph(reader.GetString("user_name")); cell = row.Cells[5]; cell.AddParagraph(reader.GetInt64("size").ToString()); cell = row.Cells[6]; cell.AddParagraph(reader.GetDateTime("download_date").ToString()); rowCount++; } } conn.Close(); } } catch (Exception exception) { } table.SetEdge(0, 0, 7, rowCount, Edge.Box, BorderStyle.Single, 1.5, Colors.Black); document.LastSection.Add(table); }
public static Table CreateSimpleRow(string[] strArrayRow, string[] strArrayRowSize, string fontName, Color fontColor, Color shadeColor, Unit fontSize, ParagraphAlignment alignment, double borderSize, double edgeSize, bool isBold) { Table table = new Table(); table.Borders.Width = borderSize; for (int i = 0; i < strArrayRow.GetLength(0); i++) { table.AddColumn(strArrayRowSize[i]); } Row row = table.AddRow(); row.Format.Alignment = alignment; row.Format.Font.Bold = isBold; row.Format.Font.Name = fontName; row.Format.Font.Color = fontColor; row.Format.Font.Size = fontSize; row.Shading.Color = shadeColor; row.VerticalAlignment = VerticalAlignment.Center; Cell cell; for (int i = 0; i < strArrayRow.GetLength(0); i++) { cell = row.Cells[i]; cell.AddParagraph(strArrayRow[i]); } table.SetEdge(0, 0, strArrayRow.GetLength(0), 1, Edge.Box, BorderStyle.Single, edgeSize, Colors.Black); return table; }