/// <summary> /// Write the summary report to the specified writer. /// </summary> /// <param name="storage">The data store to query</param> /// <param name="simulationName">The simulation name to produce a summary report for</param> /// <param name="writer">Text writer to write to</param> /// <param name="apsimSummaryImageFileName">The file name for the logo. Can be null</param> /// <param name="outtype">Indicates the format to be produced</param> /// <param name="darkTheme">Whether or not the dark theme should be used.</param> public static void WriteReport( IDataStore storage, string simulationName, TextWriter writer, string apsimSummaryImageFileName, OutputType outtype, bool darkTheme) { Document document = null; RtfDocumentRenderer renderer = null; if (outtype == OutputType.html) { writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.WriteLine("<html>"); writer.WriteLine("<head>"); writer.WriteLine("<meta content='text/html; charset=UTF-8; http-equiv='content-type'>"); writer.WriteLine("<style>"); if (darkTheme) { writer.WriteLine("h2 { color:white; } "); writer.WriteLine("h3 { color:white; } "); writer.WriteLine("table { border:1px solid white; }"); } else { writer.WriteLine("h2 { color:darkblue; } "); writer.WriteLine("h3 { color:darkblue; } "); writer.WriteLine("table { border:1px solid black; }"); writer.WriteLine("th { background-color: palegoldenrod}"); writer.WriteLine("tr.total { color:darkorange; }"); } writer.WriteLine("table { border-collapse:collapse; width:100%; table-layout:fixed; text-align:left; }"); writer.WriteLine("table.headered {text-align:right; }"); writer.WriteLine("tr.total { font-weight:bold; }"); writer.WriteLine("table.headered td.col1 { text-align:left; font-weight:bold; }"); writer.WriteLine("td { border:1px solid; }"); writer.WriteLine("th { border:1px solid; text-align:right; }"); writer.WriteLine("th.col1 { text-align:left; }"); writer.WriteLine("</style>"); writer.WriteLine("</head>"); writer.WriteLine("<body>"); writer.WriteLine("<a href=\"#log\">Simulation log</a>"); } else if (outtype == OutputType.rtf) { document = new Document(); renderer = new RtfDocumentRenderer(); // Get the predefined style Normal. Style style = document.Styles["Normal"]; // Because all styles are derived from Normal, the next line changes the // font of the whole document. Or, more exactly, it changes the font of // all styles and paragraphs that do not redefine the font. style.Font.Name = "Arial"; // Heading1 to Heading9 are predefined styles with an outline level. An outline level // other than OutlineLevel.BodyText automatically creates the outline (or bookmarks) // in PDF. style = document.Styles["Heading2"]; style.Font.Size = 14; style.Font.Bold = true; style.Font.Color = Colors.DarkBlue; style.ParagraphFormat.PageBreakBefore = false; style.ParagraphFormat.SpaceAfter = 3; style.ParagraphFormat.SpaceBefore = 16; style = document.Styles["Heading3"]; style.Font.Size = 12; style.Font.Bold = true; style.Font.Color = Colors.DarkBlue; style.ParagraphFormat.SpaceBefore = 10; style.ParagraphFormat.SpaceAfter = 2; // Create a new style called Monospace based on style Normal style = document.Styles.AddStyle("Monospace", "Normal"); System.Drawing.FontFamily monoFamily = new System.Drawing.FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace); style.Font.Name = monoFamily.Name; Section section = document.AddSection(); } // Get the initial conditions table. DataTable initialConditionsTable = storage.Reader.GetData(simulationName: simulationName, tableName: "_InitialConditions"); if (initialConditionsTable != null) { // Convert the '_InitialConditions' table in the DataStore to a series of // DataTables for each model. List <DataTable> tables = new List <DataTable>(); ConvertInitialConditionsToTables(initialConditionsTable, tables); // Now write all tables to our report. for (int i = 0; i < tables.Count; i += 2) { // Only write something to the summary file if we have something to write. if (tables[i].Rows.Count > 0 || tables[i + 1].Rows.Count > 0) { string heading = tables[i].TableName; WriteHeading(writer, heading, outtype, document); // Write the manager script. if (tables[i].Rows.Count == 1 && tables[i].Rows[0][0].ToString() == "Script code: ") { WriteScript(writer, tables[i].Rows[0], outtype, document); } else { // Write the properties table if we have any properties. if (tables[i].Rows.Count > 0) { WriteTable(writer, tables[i], outtype, "PropertyTable", document); } // Write the general data table if we have any data. if (tables[i + 1].Rows.Count > 0) { WriteTable(writer, tables[i + 1], outtype, "ApsimTable", document); } } if (outtype == OutputType.html) { writer.WriteLine("<br/>"); } } } } // Write out all messages. WriteHeading(writer, "Simulation log:", outtype, document, "log"); DataTable messageTable = GetMessageTable(storage, simulationName); WriteMessageTable(writer, messageTable, outtype, false, "MessageTable", document); if (outtype == OutputType.html) { writer.WriteLine("</body>"); writer.WriteLine("</html>"); } else if (outtype == OutputType.rtf) { string rtf = renderer.RenderToString(document, Path.GetTempPath()); writer.Write(rtf); } }
/////////////////////// /// private void CreatePDF() { #region FillDataTab DataTable dataTable = new DataTable(); dataTable.Columns.Add("Parametr"); dataTable.Columns.Add("Value"); dataTable.Columns.Add("Unit"); DataRow dr1 = dataTable.NewRow(); dr1[0] = ""; dr1[1] = Department; dr1[2] = ""; dataTable.Rows.Add(dr1); DataRow dr2 = dataTable.NewRow(); dr2[0] = ""; dr2[1] = Fio; dr2[2] = ""; dataTable.Rows.Add(dr2); DataRow dr3 = dataTable.NewRow(); dr3[0] = ""; dr3[1] = TireType; dr2[2] = ""; dataTable.Rows.Add(dr3); DataRow dr4 = dataTable.NewRow(); dr4[0] = ""; dr4[1] = TireNomber; dr4[2] = ""; dataTable.Rows.Add(dr4); DataRow dr5 = dataTable.NewRow(); dr5[0] = ""; dr5[1] = TireSize; dr5[2] = ""; dataTable.Rows.Add(dr5); DataRow dr6 = dataTable.NewRow(); dr6[0] = ""; dr6[1] = TestTypeProp.Name; dr6[2] = ""; dataTable.Rows.Add(dr6); DataRow dr7 = dataTable.NewRow(); dr7[0] = "Температура"; dr7[1] = temperature; dr7[2] = "°C"; dataTable.Rows.Add(dr7); DataRow dr8 = dataTable.NewRow(); dr8[0] = ""; dr8[1] = "Формула"; dr8[2] = ""; dataTable.Rows.Add(dr8); DataRow dr9 = dataTable.NewRow(); dr9[0] = ""; dr9[1] = TestTypeProp.ForceName; dr9[2] = ""; dataTable.Rows.Add(dr9); DataRow dr10 = dataTable.NewRow(); dr10[0] = ""; dr10[1] = TestTypeProp.HalfForceName; dr10[2] = ""; dataTable.Rows.Add(dr10); DataRow dr11 = dataTable.NewRow(); dr11[0] = ""; dr11[1] = TestTypeProp.WayName; dr11[2] = ""; dataTable.Rows.Add(dr11); DataRow dr12 = dataTable.NewRow(); dr12[0] = ""; dr12[1] = TestTypeProp.HalfWayName; dr12[2] = ""; dataTable.Rows.Add(dr12); DataRow dr13 = dataTable.NewRow(); dr13[0] = ""; dr13[1] = TestTypeProp.KoefName; dr13[2] = ""; dataTable.Rows.Add(dr13); DataRow dr14 = dataTable.NewRow(); dr14[0] = ""; dr14[1] = TestTypeProp.Formula; dr14[2] = ""; dataTable.Rows.Add(dr14); DataRow dr15 = dataTable.NewRow(); dr15[0] = ""; dr15[1] = TestTypeProp.ForceValue; dr15[2] = ""; dataTable.Rows.Add(dr15); DataRow dr16 = dataTable.NewRow(); dr16[0] = ""; dr16[1] = TestTypeProp.HalfForceValue; dr16[2] = ""; dataTable.Rows.Add(dr16); DataRow dr17 = dataTable.NewRow(); dr17[0] = ""; dr17[1] = TestTypeProp.WayValue; dr17[2] = ""; dataTable.Rows.Add(dr17); DataRow dr18 = dataTable.NewRow(); dr18[0] = ""; dr18[1] = TestTypeProp.HalfWayValue; dr18[2] = ""; dataTable.Rows.Add(dr18); DataRow dr19 = dataTable.NewRow(); dr19[0] = ""; dr19[1] = TestTypeProp.KoefValue; dr19[2] = ""; dataTable.Rows.Add(dr19); DataRow dr20 = dataTable.NewRow(); dr20[0] = ""; dr20[1] = Radius; dr20[2] = ""; dataTable.Rows.Add(dr20); DataRow dr21 = dataTable.NewRow(); dr21[0] = ""; dr21[1] = RealGetForceMax; dr21[2] = ""; dataTable.Rows.Add(dr21); DataRow dr22 = dataTable.NewRow(); dr22[0] = ""; dr22[1] = Pressure; dr22[2] = ""; dataTable.Rows.Add(dr22); DataRow dr23 = dataTable.NewRow(); dr23[0] = ""; dr23[1] = UpperLoad; dr23[2] = ""; dataTable.Rows.Add(dr23); #endregion switch (_testType.Id) { case 1: _testType.HalfForceValue = HalfForce_1; _testType.HalfWayValue = HalfPos_1; _testType.ForceValue = ST_Force_1; _testType.WayValue = ST_Way_1; _testType.KoefValue = Koef_1; break; case 2: _testType.HalfForceValue = HalfForce_2; _testType.HalfWayValue = HalfPos_2; _testType.ForceValue = ST_Force_2; _testType.WayValue = ST_Way_2; _testType.KoefValue = Koef_2; break; case 3: _testType.HalfForceValue = HalfForce_3; _testType.HalfWayValue = HalfPos_3; _testType.ForceValue = ST_Force_3; _testType.WayValue = ST_Way_3; _testType.KoefValue = Koef_3; break; } //try //{ PDF_Tab pDF_Tab = new PDF_Tab(/*"/Projects/PDF/Invoice/invoice.xml",*/ dataTable, _testType); var document = pDF_Tab.CreateDocument(); document.UseCmykColor = true; var pdfRenderer = new PdfDocumentRenderer(true); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); var filename = "Invoice.pdf"; pdfRenderer.Save(filename); Process.Start(filename); var filenameRTF = "Invoice.rtf"; RtfDocumentRenderer rtf = new RtfDocumentRenderer(); rtf.Render(document, filenameRTF, null); Process.Start(filenameRTF); //} //catch (Exception ex) { } }
/// <summary> /// The close. /// </summary> public override void Close() { var r = new RtfDocumentRenderer(); r.Render(this.Document, this.Output, Path.GetTempPath()); }
public static void OutputPDF(string path, List <DesignatorGroup> groups, HeaderBlock header, string file, bool rtf = false) { Console.WriteLine("Generating " + file + "..."); // document setup var doc = new Document(); doc.DefaultPageSetup.PageFormat = PageFormat.A4; doc.DefaultPageSetup.Orientation = Orientation.Landscape; doc.DefaultPageSetup.TopMargin = "1.5cm"; doc.DefaultPageSetup.BottomMargin = "1.5cm"; doc.DefaultPageSetup.LeftMargin = "1.5cm"; doc.DefaultPageSetup.RightMargin = "1.5cm"; doc.Styles["Normal"].Font.Name = "Arial"; var footer = new Paragraph(); footer.AddTab(); footer.AddPageField(); footer.AddText(" of "); footer.AddNumPagesField(); footer.Format.Alignment = ParagraphAlignment.Center; // generate content var section = doc.AddSection(); section.Footers.Primary.Add(footer.Clone()); section.Footers.EvenPage.Add(footer.Clone()); PDFCreateHeader(ref section, header); var para = section.AddParagraph(); var table = PDFCreateTable(ref section); // BOM table int i = 1; foreach (DesignatorGroup g in groups) { // check for groups that are entire "no part" bool all_no_part = true; foreach (Component c in g.comp_list) { if (!c.no_part) { all_no_part = false; } } if (all_no_part) { continue; } // group header row var row = table.AddRow(); row.Shading.Color = Colors.LightGray; row.Cells[0].MergeRight = 6; row.Cells[0].Format.Alignment = ParagraphAlignment.Left; DefaultComp def = Component.FindDefaultComp(g.designator); if (def != null) { var p = row.Cells[0].AddParagraph(def.long_name); p.Format.Font.Bold = true; if (def.has_default) { row.Cells[0].AddParagraph("All " + def.default_type + " unless otherwise stated"); } } else { var p = row.Cells[0].AddParagraph(g.designator); p.Format.Font.Bold = true; } foreach (Component c in g.comp_list) { if (c.no_part) { continue; } row = table.AddRow(); row.Cells[0].AddParagraph(i++.ToString()); row.Cells[1].AddParagraph((c.count + 1).ToString()); row.Cells[2].AddParagraph(c.reference); row.Cells[3].AddParagraph(c.value); string temp = c.footprint_normalized; if (c.code != null) { temp += ", " + c.code; } if (c.precision != null) { temp += ", " + c.precision; } row.Cells[4].AddParagraph(temp); //row.Cells[4].AddParagraph(c.footprint_normalized); row.Cells[5].AddParagraph(c.part_no); row.Cells[6].AddParagraph(c.note); } } // generate PDF file if (!rtf) { var pdfRenderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); pdfRenderer.Document = doc; pdfRenderer.RenderDocument(); pdfRenderer.PdfDocument.Save(file); } else { var rtfRenderer = new RtfDocumentRenderer(); rtfRenderer.Render(doc, file, null); } }
/// <summary> /// Write the summary report to the specified writer. /// </summary> /// <param name="dataStore">The data store to write a summary report from</param> /// <param name="simulationName">The simulation name to produce a summary report for</param> /// <param name="writer">Text writer to write to</param> /// <param name="apsimSummaryImageFileName">The file name for the logo. Can be null</param> /// <param name="outtype">Indicates the format to be produced</param> public static void WriteReport( DataStore dataStore, string simulationName, TextWriter writer, string apsimSummaryImageFileName, OutputType outtype) { Document document = null; RtfDocumentRenderer renderer = null; if (outtype == OutputType.html) { writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.WriteLine("<html>"); writer.WriteLine("<body>"); } else if (outtype == OutputType.rtf) { document = new Document(); renderer = new RtfDocumentRenderer(); // Get the predefined style Normal. Style style = document.Styles["Normal"]; // Because all styles are derived from Normal, the next line changes the // font of the whole document. Or, more exactly, it changes the font of // all styles and paragraphs that do not redefine the font. style.Font.Name = "Arial"; // Heading1 to Heading9 are predefined styles with an outline level. An outline level // other than OutlineLevel.BodyText automatically creates the outline (or bookmarks) // in PDF. style = document.Styles["Heading2"]; style.Font.Size = 14; style.Font.Bold = true; style.Font.Color = Colors.DarkBlue; style.ParagraphFormat.PageBreakBefore = false; style.ParagraphFormat.SpaceAfter = 3; style.ParagraphFormat.SpaceBefore = 16; style = document.Styles["Heading3"]; style.Font.Size = 12; style.Font.Bold = true; style.Font.Color = Colors.DarkBlue; style.ParagraphFormat.SpaceBefore = 10; style.ParagraphFormat.SpaceAfter = 2; // Create a new style called Monospace based on style Normal style = document.Styles.AddStyle("Monospace", "Normal"); System.Drawing.FontFamily monoFamily = new System.Drawing.FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace); style.Font.Name = monoFamily.Name; Section section = document.AddSection(); } // Get the initial conditions table. DataTable initialConditionsTable = dataStore.GetData(simulationName, "InitialConditions"); if (initialConditionsTable != null) { // Convert the 'InitialConditions' table in the DataStore to a series of // DataTables for each model. List <DataTable> tables = new List <DataTable>(); ConvertInitialConditionsToTables(initialConditionsTable, tables); // Now write all tables to our report. for (int i = 0; i < tables.Count; i += 2) { // Only write something to the summary file if we have something to write. if (tables[i].Rows.Count > 0 || tables[i + 1].Rows.Count > 0) { string heading = tables[i].TableName; WriteHeading(writer, heading, outtype, document); // Write the manager script. if (tables[i].Rows.Count == 1 && tables[i].Rows[0][0].ToString() == "Script code: ") { WriteScript(writer, tables[i].Rows[0], outtype, document); } else { // Write the properties table if we have any properties. if (tables[i].Rows.Count > 0) { WriteTable(writer, tables[i], outtype, "PropertyTable", document); } // Write the general data table if we have any data. if (tables[i + 1].Rows.Count > 0) { WriteTable(writer, tables[i + 1], outtype, "ApsimTable", document); } } if (outtype == OutputType.html) { writer.WriteLine("<br/>"); } } } } // Write out all messages. WriteHeading(writer, "Simulation log:", outtype, document); DataTable messageTable = GetMessageTable(dataStore, simulationName); WriteMessageTable(writer, messageTable, outtype, false, "MessageTable", document); if (outtype == OutputType.html) { writer.WriteLine("</body>"); writer.WriteLine("</html>"); } else if (outtype == OutputType.rtf) { string rtf = renderer.RenderToString(document, Path.GetTempPath()); writer.Write(rtf); } }
public static bool SendMail(string destination, string subject, string body, object sessionLogo, bool ingresoSitio) { SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SMTP"], Convert.ToInt32(ConfigurationManager.AppSettings["PortSMTP"])); client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["usuarioSMTP"], ConfigurationManager.AppSettings["passwordSMTP"]); MailAddress from = new MailAddress(ConfigurationManager.AppSettings["mailSender"], "Travel Pay", System.Text.Encoding.UTF8); MailAddress to = new MailAddress(destination); MailMessage message = new MailMessage(from, to); message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = subject; message.SubjectEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; string logo = ""; string encabezado = "<table align=Center style='border:solid 1px black;width:675px'><tr><td align=center><img src='" + logo + "'></td></tr><tr><td align=left>"; Document document = CreateDocument(); document.UseCmykColor = true; // string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document); #if true_ RtfDocumentRenderer renderer = new RtfDocumentRenderer(); renderer.Render(document, "HelloWorld.rtf", null); #endif // ----- Unicode encoding and font program embedding in MigraDoc is demonstrated here ----- // A flag indicating whether to create a Unicode PDF or a WinAnsi PDF file. // This setting applies to all fonts used in the PDF document. // This setting has no effect on the RTF renderer. bool unicode = false; // An enum indicating whether to embed fonts or not. // This setting applies to all font programs used in the document. // This setting has no effect on the RTF renderer. // (The term 'font program' is used by Adobe for a file containing a font. Technically a 'font file' // is a collection of small programs and each program renders the glyph of a character when executed. // Using a font in PDFsharp may lead to the embedding of one or more font programms, because each outline // (regular, bold, italic, bold+italic, ...) has its own fontprogram) PdfFontEmbedding embedding = PdfFontEmbedding.Always; // Set to PdfFontEmbedding.None or PdfFontEmbedding.Always only // ---------------------------------------------------------------------------------------- // Create a renderer for the MigraDoc document. PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding); // Associate the MigraDoc document with a renderer pdfRenderer.Document = document; // Layout and render document to PDF pdfRenderer.RenderDocument(); // Save the document... string filename = AppDomain.CurrentDomain.BaseDirectory + "HelloWorld2.pdf"; pdfRenderer.PdfDocument.Save(filename); pdfRenderer.PdfDocument.Close(); message.Attachments.Add(new Attachment(filename)); //message.Attachments.Add(new Attachment()); StringBuilder legal = new StringBuilder(); if (ingresoSitio) { legal.Append("<p align=center>Ingresar al Sitio</p> "); } legal.Append("<br><font size=1>La información contenida en este correo es confidencial y para uso exclusivo "); legal.Append("de los destinatarios del mismo. Esta prohibido a las personas o entidades "); legal.Append("que no sean los destinatarios de este correo, realizar cualquier tipo de "); legal.Append("modificación, copia o distribución del mismo. Toda la información contenida "); legal.Append("en este email está sujeta a los términos y condiciones generales que se "); legal.Append("establecen en la Sección Legales. Si Usted recibe este correo por error, "); legal.Append("tenga a bien notificar al emisor y eliminarlo.</font> "); string footer = "</td></tr><tr><td><br><br><br></td></tr><tr><td align=center>" + legal + "</td></tr></table>"; message.Body = encabezado + body + footer; client.Send(message); return(true); }