static void Main(string[] args) { // Initialize the engine Report.Init(); // Open template file and create output file FileStream template = File.OpenRead("../../../../../Data/Samples/Source/WW-Common List.docx"); FileStream output = File.Create("../../../../../Data/Samples/Destination/Xml Common List.docx"); // Create report process Report myReport = new ReportPdf(template, output); // Open an inputfilestream for our data file FileStream Xml = File.OpenRead("../../../../../Data/Data Source/WW-Customers.xml"); // Open a data object to connect to our xml file IReportDataSource data = new XmlDataSourceImpl(Xml, false); // Run the report process myReport.ProcessSetup(); // The second parameter is "" to tell the process that our data is the default data source myReport.ProcessData(data, "Customers"); myReport.ProcessComplete(); // Close out of our template file and output output.Close(); template.Close(); Xml.Close(); // Opens the finished report string fullPath = Path.GetFullPath("../../../../../Data/Samples/Destination/Xml Common List.docx"); System.Diagnostics.Process.Start(fullPath); }
public void DB2Report() { // Initialize the engine Report.Init(); // Open template file and create output file FileStream template = File.OpenRead("../../../Samples/Windward Trucking 2 - Template.docx"); FileStream output = File.Create("../../../Samples/Xml Report.pdf"); // Create report process Report myReport = new ReportPdf(template, output); // Open an inputfilestream for our data file FileStream Xml = File.OpenRead("../../../Samples/Windward Trucking 2 - Data.xml"); // Open a data object to connect to our xml file IReportDataSource data = new XmlDataSourceImpl(Xml, false); // Run the report process myReport.ProcessSetup(); // The second parameter is "" to tell the process that our data is the default data source myReport.ProcessData(data, ""); myReport.ProcessComplete(); // Close out of our template file and output output.Close(); template.Close(); Xml.Close(); // Opens the finished report string fullPath = Path.GetFullPath("../../../Samples/Xml Report.pdf"); System.Diagnostics.Process.Start(fullPath); }
public void RunReport() { Console.Out.WriteLine(string.Format("Requesting report {0}", Path.GetFileName(reportFilename))); // this will not return until there is an available semaphore. When it returns, the used semaphore count is incremented by one. sem.WaitOne(); try { Console.Out.WriteLine(string.Format(" processing report {0}", Path.GetFileName(reportFilename))); // Open template file and create output file using (FileStream template = File.OpenRead(templateFilename)) { using (FileStream output = File.Create(reportFilename)) { // Create report process // !!!!! you MUST have using on this to insure it is closed and the thread count for the engine is decreased !!!!! using (Report myReport = new ReportDocx(template, output)) { myReport.ProcessSetup(); // remove this - this is here insure that all threads try to run at once. Thread.Sleep(10 * 1000); // Open an inputfilestream for our data file FileStream Xml = File.OpenRead(xmlDataFilename); // Open a data object to connect to our xml file IReportDataSource data = new XmlDataSourceImpl(Xml, false); // Close out of our template file and output Xml.Close(); // Run the report process myReport.ProcessData(data, ""); myReport.ProcessComplete(); } } } } finally { Console.Out.WriteLine(string.Format(" report completed (releasing semaphore) {0}", Path.GetFileName(reportFilename))); // you must call this in a finally block so it is always called. // this decrements the used semaphore count by one. sem.Release(1); } }
private static void RunReport(string templateFilename, string outputFilename, Dictionary <string, object> adHocVariables) { // get the report ready to run. using (Stream template = new FileStream(templateFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (Stream output = new FileStream(outputFilename, FileMode.Create, FileAccess.Write, FileShare.None)) { using (Report report = new ReportDocx(template, output)) { report.ProcessSetup(); // Create the datasource - SouthWind.xml. // We need the XSD too so it knows the type of nodes. using (Stream xmlStream = new FileStream(Path.GetFullPath("../../SouthWind.xml"), FileMode.Open, FileAccess.Read, FileShare.Read)) { using (Stream xsdStream = new FileStream(Path.GetFullPath("../../SouthWind.xsd"), FileMode.Open, FileAccess.Read, FileShare.Read)) { using (XmlDataSourceImpl datasource = new XmlDataSourceImpl(xmlStream, xsdStream, true)) { // set the variables to provide list results for each var report.Parameters = adHocVariables; // run the datasource report.ProcessData(datasource, ""); } } } // and we're done! report.ProcessComplete(); output.Close(); } } } Console.Out.WriteLine(string.Format("Completed: {0}", outputFilename)); }
protected void Page_Load(object sender, EventArgs e) { string basePath = Request.PhysicalApplicationPath + "\\"; // Initialize the engine. License and configuration settings in web.config. Report.Init(); // Open template file FileStream template = File.OpenRead(basePath + "Windward Trucking 2 - Template.docx"); // Create report process Report myReport = new ReportPdf(template); // Open data file FileStream Xml = File.OpenRead(basePath + "Windward Trucking 2 - Data.xml"); // Make a data object to connect to our xml file IReportDataSource data = new XmlDataSourceImpl(Xml, false); // Run the report process myReport.ProcessSetup(); // The second parameter is "" to tell the process that our data is the unnamed data source myReport.ProcessData(data, ""); myReport.ProcessComplete(); // Close out of our template file template.Close(); Xml.Close(); // Opens the finished report //Response.ContentType = "application/pdf"; // this would have the pdf open in the browser (disable content-disposition:attachment if you want this) Response.ContentType = "application/save"; // this is used with content-disposition to give the proper name of the file Response.AppendHeader("content-disposition", "attachment; filename=\"Report.pdf\""); Response.BinaryWrite(((MemoryStream)myReport.GetReport()).ToArray()); Response.End(); // Must be called for MS Office documents }
/** * Sample document demonstrating how to include Error Handling into a java app and print the error stream to a .txt file * * @author Adam Austin */ static void Main(string[] args) { try { // Initialize the engine Report.Init(); // To generate a report, first we need a Report object. For now, we're using the // pdf format to output. FileStream template = File.OpenRead("../../../Samples/Smart Energy Template.docx"); FileStream reportStream = File.Create("../../../Samples/report.pdf"); Report report = new ReportPdf(template, reportStream); // Preparation... Console.Out.WriteLine("Generating report..."); report.ProcessSetup(); // Set Track Verify and Error Handling issues during report generation based off a command line argument string trackErrorSetting = ""; if (args.Length > 0) { trackErrorSetting = args[0]; } switch (trackErrorSetting) { case ("0"): Console.Out.WriteLine("Track Errors: None"); report.TrackErrors = (int)Report.ERROR_HANDLING.NONE; break; case ("1"): Console.Out.WriteLine("Track Errors: Error Handling"); report.TrackErrors = (int)Report.ERROR_HANDLING.TRACK_ERRORS; break; case ("2"): Console.Out.WriteLine("Track Errors: Verify"); report.TrackErrors = (int)Report.ERROR_HANDLING.VERIFY; break; case ("3"): default: Console.Out.WriteLine("Track Errors: All"); report.TrackErrors = (int)Report.ERROR_HANDLING.ALL; break; } // Set up the data hash map. var dataProviders = new Dictionary <string, IReportDataSource>(); // Create an instance of DataSourceProvider System.Xml.XPath.XPathDocument Xml1 = new System.Xml.XPath.XPathDocument(File.OpenRead("../../../Samples/Smart Energy - Broken.xml")); IReportDataSource datasource = new XmlDataSourceImpl(Xml1); // Add the data source to the data hash map dataProviders.Add("", datasource); // Process the data stored in the hash map report.ProcessData(dataProviders); // And... DONE! report.ProcessComplete(); reportStream.Close(); template.Close(); // Print errors found by Error Handling and Verify to the command line and the file "Issues.txt" ErrorInfo outputissues = report.GetErrorInfo(); java.util.List errors = outputissues.getErrors(); Console.Out.WriteLine(); Console.Out.WriteLine("---------------------------------------------------"); Console.Out.WriteLine("Errors found during Verify upon Report Generation:"); Console.Out.WriteLine("---------------------------------------------------"); using (System.IO.StreamWriter file = new System.IO.StreamWriter("../../../Samples/Issues.txt")) { file.WriteLine("---------------------------------------------------"); file.WriteLine("Errors found by Verify upon Report Generation:"); file.WriteLine("---------------------------------------------------"); // Print every issue to the command line and the isseus.txt file for (int i = 0; i < errors.size(); i++) { Console.Out.WriteLine(((Issue)errors.get(i)).getMessage()); file.WriteLine(((Issue)errors.get(i)).getMessage()); } } } catch (Exception e) { Console.Out.WriteLine(e.StackTrace.ToString()); } Console.Out.WriteLine("\n\nGeneration finished. Click \"Enter\" to dismiss window."); Console.In.Read(); }
/// <summary> /// Create a report using Windward Reports. /// </summary> /// <param name="args">run with no parameters to list out usage.</param> static void Main(string[] args) { // // added this code to allow the example to run with a default set of parameters and return a result // //hard-code the arguments for the sample templates that ship with the example CommandLine cmdLine; if (args.Length < 2) { string[] exargs = { "InternetMarketingReport.docx", "testxmlreport.pdf", "-xml:INTMARKETING", "InternetMarketingData.xml" }; // if no arguments, then we list out the usage. Console.WriteLine("\n\n\nPress any key to display the usage parameters..."); Console.ReadKey(); DisplayUsage(); Console.WriteLine("\n\n\nPress any key to run the example with default parameters..."); Console.ReadKey(); cmdLine = CommandLine.Factory(exargs); } else { cmdLine = CommandLine.Factory(args); } // // Uncomment the following code to allow processing of the commandline parameters (other than the defaults) //and change all references from "exargs" to "args" // if no arguments, then we list out the usage. //if (args.Length < 2) // { // DisplayUsage(); // return; // } // parse the arguments passed in. This method makes no calls to Windward, it merely organizes the passed in arguments. // the try here is so we can print out an exception if it is thrown. This code does minimal error checking and no other // exception handling to keep it simple & clear. try { // This turns on log4net logging. You can also call log4net.Config.XmlConfigurator.Configure(); directly. // If you do not make this call, then there will be no logging (which you may want off). BasicConfigurator.Configure(); // Initialize the reporting engine. This will throw an exception if the engine is not fully installed or you // do not have a valid license key in RunReportXml.exe.config. Report.Init(); // get the template and output file streams. using (Stream template = new FileStream(cmdLine.TemplateFilename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (Stream output = new FileStream(cmdLine.ReportFilename, FileMode.Create, FileAccess.Write, FileShare.None)) { Console.Out.WriteLine(string.Format("Template: {0}", cmdLine.TemplateFilename)); Console.Out.WriteLine(string.Format("Report: {0}", cmdLine.ReportFilename)); // Create the report object, based on the file extension using (Report report = new ReportPdf(template, output)) { // This first call parses the template and prepares the report so we can apply data to it. report.ProcessSetup(); // If we have a datasource, we set it up. if (!string.IsNullOrEmpty(cmdLine.DatasourceFilename)) { Console.Out.WriteLine(string.Format("XML datasource: {0}", cmdLine.DatasourceFilename)); using (Stream dsStream = new FileStream(cmdLine.DatasourceFilename, FileMode.Open, FileAccess.Read)) { using (XmlDataSourceImpl datasource = new XmlDataSourceImpl(dsStream, false)) { // Assign any passed variables. report.Parameters = cmdLine.Map; // this applies the datasource to the report populating the tags. report.ProcessData(datasource, cmdLine.DatasourceName); } } } // Now that all the data has been applied, we generate the final output report. This does the // page layout and then writes out the output file. report.ProcessComplete(); Console.Out.WriteLine(string.Format("{0} built, {1} pages long", cmdLine.ReportFilename, report.NumPages)); // need a launcher for the result Process.Start(cmdLine.ReportFilename); } } } } catch (Exception ex) { while (ex != null) { Console.Error.WriteLine(string.Format("Error: {0}\n stack: {1}\n", ex.Message, ex.StackTrace)); ex = ex.InnerException; } throw; } }
protected void Page_Load(object sender, EventArgs e) { Stream template = null; Stream data = null; Report proc; try { // get the report files string templateFile = Request.PhysicalApplicationPath + "files\\Example_Template.docx"; template = new FileStream(templateFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // create the report string contentType; switch ((int)Session["report"]) { case 0: contentType = "application/pdf"; proc = new ReportPdf(template); break; case 1: contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; proc = new ReportDocx(template); break; case 2: contentType = "text/html"; proc = new ReportHtml(template); ((ReportHtml)proc).SetImagePath(Request.PhysicalApplicationPath + "images", "images", "wr_"); break; default: lblResult.Text = "Error: unknown report type " + Session["report"]; return; } proc.ProcessSetup(); // set variables Dictionary <string, object> map = new Dictionary <string, object>(); map.Add("LeaveRequestId", Session["var"]); map.Add("CSRName", "John Brown"); // apply data data = new FileStream(Request.PhysicalApplicationPath + "files\\Example_Data.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); IReportDataSource ds = new XmlDataSourceImpl(data, false); proc.Parameters = map; proc.ProcessData(ds, ""); ds.Close(); proc.ProcessComplete(); // get the output and display it Response.ContentType = contentType; Response.BinaryWrite(((MemoryStream)proc.GetReport()).ToArray()); proc.Close(); } catch (Exception ex) { lblResult.Text = ex.Message; return; } // close everything finally { if (template != null) { template.Close(); } if (data != null) { data.Close(); } } // this will throw an exception so we have it here at the end - must be last line of code! Response.End(); }
static void Main(string[] args) { if (string.IsNullOrEmpty(fromEmailAddress) || string.IsNullOrEmpty(toEmailAddress) || string.IsNullOrEmpty(emailServer)) { Console.Error.WriteLine("please enter values for email address, password, server, etc."); Console.Out.WriteLine("press any key to cancel program"); Console.ReadKey(); return; } const string subject = "Windward Reports Test Message"; const string body = "The report is attached to this email"; MailAddress fromAddress = new MailAddress(fromEmailAddress); MailAddress toAddress = new MailAddress(toEmailAddress); // gmail uses port 587 SmtpClient smtp; if (emailServer.ToLower().Contains(".gmail.")) { smtp = new SmtpClient() { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword), Timeout = 10000 } } ; else { smtp = new SmtpClient(emailServer); if (!string.IsNullOrEmpty(fromPassword)) { smtp.Credentials = new System.Net.NetworkCredential(fromAddress.Address, fromPassword); } } // Initialize the engine Report.Init(); // Open template file and create output stream FileStream template = File.OpenRead("../../../Samples/Email Example Template.docx"); MemoryStream output = new MemoryStream(); // Create report process ReportPdf myReport = new ReportPdf(template, output); // Open an inputfilestream for our data file FileStream Xml = File.OpenRead("../../../Samples/Windward Trucking 2 - Data.xml"); // Open a data object to connect to our xml file IReportDataSource data = new XmlDataSourceImpl(Xml, false); // Run the report process myReport.ProcessSetup(); // The second parameter is the name of the data source myReport.ProcessData(data, "FD"); myReport.ProcessComplete(); using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { // Sets up the name and file type of the stream System.Net.Mime.ContentType content = new System.Net.Mime.ContentType(); content.MediaType = System.Net.Mime.MediaTypeNames.Application.Pdf; content.Name = "test.pdf"; output.Position = 0; // reset the position to the beginning of the stream - Don't forget! System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(output, content); message.Attachments.Add(attachment); smtp.Send(message); } //close out of our template file and output template.Close(); Xml.Close(); output.Close(); }